1 /*
2  * Copyright (c) 2020 Intel Corporation
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 #ifndef __MSGDEV_H__
7 #define __MSGDEV_H__
8 
9 /* Define this to enable logging of every event as it is processed to
10  * carefully inspect behavior.  Note that at high event rates (see
11  * MAX_EVENT_DELAY_TICKS) the log backend won't be able to keep up and
12  * that the log processing will add CPU load that is not accounted for
13  * in AVERAGE_LOAD_TARGET_PCT.  Disable for more accurate statistics
14  * measurement.  Note that if you don't want the log subsystem
15  * throttling to drop messages, you'll probably want to increase
16  * MAX_EVENT_DELAY_TICKS too, to slow down the reporting.
17  */
18 #define LOG_EVERY_EVENT 1
19 
20 /* Number of worker threads, each at a separate priority, split evenly
21  * between cooperative and preemptible priorities.
22  */
23 #define NUM_THREADS 4
24 
25 /* The proc_cyc duty cycle parameters are chosen to use approximately
26  * this fraction of one CPU's available cycles.  Default 60%
27  */
28 #define AVERAGE_LOAD_TARGET_PCT 60
29 
30 /* "Hardware interrupts" for our fake device will arrive after a
31  * random delay of between zero and this number of ticks.  The event
32  * rate should be high enough to collect enough data but low enough
33  * that it is not regular.
34  */
35 #define MAX_EVENT_DELAY_TICKS 8
36 
37 /* How many events will be sent before the test completes?  Note that
38  * we keep a naive array of latencies to compute variance, so this
39  * value has memory costs.
40  */
41 #define MAX_EVENTS 40
42 
43 /* The "messages" dispatched by our MetaIRQ thread */
44 struct msg {
45 	/* Sequence number */
46 	uint32_t seq;
47 
48 	/* Cycle time when the message was "received" */
49 	uint32_t timestamp;
50 
51 	/* Thread to which the message is targeted */
52 	uint32_t target;
53 
54 	/* Cycles of processing the message requires */
55 	uint32_t proc_cyc;
56 
57 	/* Cycles of latency before the MetaIRQ thread received the message */
58 	uint32_t metairq_latency;
59 };
60 
61 /* Initialize the fake "message" device, after this messages will
62  * begin arriving via message_dev_fetch().
63  */
64 void message_dev_init(void);
65 
66 /* Retrieve the next message from the "device", blocks until
67  * delivery
68  */
69 void message_dev_fetch(struct msg *m);
70 
71 #endif /* __MSGDEV_H__ */
72