]> git.saurik.com Git - apple/libpthread.git/blame - tests/wq_kevent.h
libpthread-454.100.8.tar.gz
[apple/libpthread.git] / tests / wq_kevent.h
CommitLineData
964d3577
A
1#define REQUESTS_LEN 4
2static struct workq_reqthreads_req_s {unsigned long priority; int count;} requests[REQUESTS_LEN];
3
4#define QOS_STR(q) (q == QOS_CLASS_USER_INTERACTIVE ? "UInter" : (q == QOS_CLASS_USER_INITIATED ? "UInit" : (q == QOS_CLASS_DEFAULT ? "Dflt" : (q == QOS_CLASS_UTILITY ? "Util" : (q == QOS_CLASS_BACKGROUND ? "BG" : "Unkn" ) ) ) ) )
5static char* describe_pri(pthread_priority_t pri){
6 qos_class_t qos;
7 unsigned long flags;
8
9 qos = _pthread_qos_class_decode(pri, NULL, &flags);
10
11 static char desc[32];
12 if (flags & _PTHREAD_PRIORITY_EVENT_MANAGER_FLAG){
13 sprintf(desc, "E:%s", QOS_STR(qos));
14 } else if (flags & _PTHREAD_PRIORITY_OVERCOMMIT_FLAG){
15 sprintf(desc, "O:%s", QOS_STR(qos));
16 } else {
17 sprintf(desc, "%s", QOS_STR(qos));
18 }
19
20 return desc;
21}
22
23static char* describe_req(void){
24 static char desc[256];
25 char *c = desc;
26
27 *c++ = '[';
28 for (int i = 0; i < REQUESTS_LEN; i++){
29 if (i) *c++ = ',';
30 c += sprintf(c, "{%s,%d}", describe_pri(requests[i].priority), requests[i].count);
31 }
32 *c++ = ']';
33 *c++ = '\0';
34
35 return desc;
36}
37
38static char *dummy_text = "Four score and seven years ago our fathers brought forth on this continent a new nation, conceived in liberty, and dedicated to the";
39// takes about 1us on my machine
40static void burn_cpu(void){
41 char key[64]; char txt[64];
42 strncpy(txt, dummy_text, 64);
43 for (int i = 0; i < 64; i++)
44 key[i] = rand() % 1;
45 setkey(key);
46 encrypt(txt, 0);
47 encrypt(txt, 1);
48}
49
50static int do_req(void){
51 int ret = sysctlbyname("debug.wq_kevent_test", NULL, NULL, requests, sizeof(requests));
52 if (ret >= 0){
53 fprintf(stderr, "wq_kevent_test(%s) -> %d\n", describe_req(), ret);
54 } else {
55 perror("debug.wk_kevent_test");
56 return errno;
57 }
58 return ret;
59}