• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2018 Google, Inc.
3  *
4  * SPDX-License-Identifier: GPL-2.0-or-later
5  *
6  * This test looks for a high number of wakeups from the schedutil governor
7  * threads.
8  */
9 
10 #define _GNU_SOURCE
11 #include <errno.h>
12 #include <pthread.h>
13 #include <sched.h>
14 #include <stdio.h>
15 #include <time.h>
16 
17 #include "tst_test.h"
18 #include "tst_safe_file_ops.h"
19 #include "tst_safe_pthread.h"
20 
21 #include "trace_parse.h"
22 
23 #define TRACE_EVENTS "sched_switch"
24 
25 #define MAX_WAKEUPS 100
26 
27 #define SLEEP_SEC 10
run(void)28 static void run(void)
29 {
30 	int i;
31 	int num_sugov_wakeups = 0;
32 
33 	tst_res(TINFO, "Observing sugov wakeups over %d sec, "
34 		"%d wakeups allowed\n", SLEEP_SEC, MAX_WAKEUPS);
35 
36 	/* configure and enable tracing */
37 	SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "0");
38 	SAFE_FILE_PRINTF(TRACING_DIR "buffer_size_kb", "16384");
39 	SAFE_FILE_PRINTF(TRACING_DIR "set_event", TRACE_EVENTS);
40 	SAFE_FILE_PRINTF(TRACING_DIR "trace", "\n");
41 	SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "1");
42 
43 	sleep(SLEEP_SEC);
44 
45 	/* disable tracing */
46 	SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "0");
47 	LOAD_TRACE();
48 
49 	for (i = 0; i < num_trace_records; i++) {
50 		if (trace[i].event_type == TRACE_RECORD_SCHED_SWITCH) {
51 			struct trace_sched_switch *t = trace[i].event_data;
52 			if (!strncmp("sugov:", t->next_comm, 6))
53 				num_sugov_wakeups++;
54 		}
55 	}
56 	printf("%d sugov wakeups occurred.\n", num_sugov_wakeups);
57 	if (num_sugov_wakeups > MAX_WAKEUPS)
58 		tst_res(TFAIL, "Too many wakeups from the schedutil "
59 			"governor.\n");
60 	else
61 		tst_res(TPASS, "Wakeups from schedutil governor were below "
62 			"threshold.\n");
63 }
64 
65 static struct tst_test test = {
66 	.test_all = run,
67 	.cleanup = trace_cleanup,
68 };
69