~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/sched_ext/scx_simple.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /tools/sched_ext/scx_simple.c (Architecture sparc64) and /tools/sched_ext/scx_simple.c (Architecture alpha)


  1 /* SPDX-License-Identifier: GPL-2.0 */              1 /* SPDX-License-Identifier: GPL-2.0 */
  2 /*                                                  2 /*
  3  * Copyright (c) 2022 Meta Platforms, Inc. and      3  * Copyright (c) 2022 Meta Platforms, Inc. and affiliates.
  4  * Copyright (c) 2022 Tejun Heo <tj@kernel.org      4  * Copyright (c) 2022 Tejun Heo <tj@kernel.org>
  5  * Copyright (c) 2022 David Vernet <dvernet@me      5  * Copyright (c) 2022 David Vernet <dvernet@meta.com>
  6  */                                                 6  */
  7 #include <stdio.h>                                  7 #include <stdio.h>
  8 #include <unistd.h>                                 8 #include <unistd.h>
  9 #include <signal.h>                                 9 #include <signal.h>
 10 #include <libgen.h>                                10 #include <libgen.h>
 11 #include <bpf/bpf.h>                               11 #include <bpf/bpf.h>
 12 #include <scx/common.h>                            12 #include <scx/common.h>
 13 #include "scx_simple.bpf.skel.h"                   13 #include "scx_simple.bpf.skel.h"
 14                                                    14 
 15 const char help_fmt[] =                            15 const char help_fmt[] =
 16 "A simple sched_ext scheduler.\n"                  16 "A simple sched_ext scheduler.\n"
 17 "\n"                                               17 "\n"
 18 "See the top-level comment in .bpf.c for more      18 "See the top-level comment in .bpf.c for more details.\n"
 19 "\n"                                               19 "\n"
 20 "Usage: %s [-f] [-v]\n"                            20 "Usage: %s [-f] [-v]\n"
 21 "\n"                                               21 "\n"
 22 "  -f            Use FIFO scheduling instead o     22 "  -f            Use FIFO scheduling instead of weighted vtime scheduling\n"
 23 "  -v            Print libbpf debug messages\n     23 "  -v            Print libbpf debug messages\n"
 24 "  -h            Display this help and exit\n"     24 "  -h            Display this help and exit\n";
 25                                                    25 
 26 static bool verbose;                               26 static bool verbose;
 27 static volatile int exit_req;                      27 static volatile int exit_req;
 28                                                    28 
 29 static int libbpf_print_fn(enum libbpf_print_l     29 static int libbpf_print_fn(enum libbpf_print_level level, const char *format, va_list args)
 30 {                                                  30 {
 31         if (level == LIBBPF_DEBUG && !verbose)     31         if (level == LIBBPF_DEBUG && !verbose)
 32                 return 0;                          32                 return 0;
 33         return vfprintf(stderr, format, args);     33         return vfprintf(stderr, format, args);
 34 }                                                  34 }
 35                                                    35 
 36 static void sigint_handler(int simple)             36 static void sigint_handler(int simple)
 37 {                                                  37 {
 38         exit_req = 1;                              38         exit_req = 1;
 39 }                                                  39 }
 40                                                    40 
 41 static void read_stats(struct scx_simple *skel     41 static void read_stats(struct scx_simple *skel, __u64 *stats)
 42 {                                                  42 {
 43         int nr_cpus = libbpf_num_possible_cpus     43         int nr_cpus = libbpf_num_possible_cpus();
 44         __u64 cnts[2][nr_cpus];                    44         __u64 cnts[2][nr_cpus];
 45         __u32 idx;                                 45         __u32 idx;
 46                                                    46 
 47         memset(stats, 0, sizeof(stats[0]) * 2)     47         memset(stats, 0, sizeof(stats[0]) * 2);
 48                                                    48 
 49         for (idx = 0; idx < 2; idx++) {            49         for (idx = 0; idx < 2; idx++) {
 50                 int ret, cpu;                      50                 int ret, cpu;
 51                                                    51 
 52                 ret = bpf_map_lookup_elem(bpf_     52                 ret = bpf_map_lookup_elem(bpf_map__fd(skel->maps.stats),
 53                                           &idx     53                                           &idx, cnts[idx]);
 54                 if (ret < 0)                       54                 if (ret < 0)
 55                         continue;                  55                         continue;
 56                 for (cpu = 0; cpu < nr_cpus; c     56                 for (cpu = 0; cpu < nr_cpus; cpu++)
 57                         stats[idx] += cnts[idx     57                         stats[idx] += cnts[idx][cpu];
 58         }                                          58         }
 59 }                                                  59 }
 60                                                    60 
 61 int main(int argc, char **argv)                    61 int main(int argc, char **argv)
 62 {                                                  62 {
 63         struct scx_simple *skel;                   63         struct scx_simple *skel;
 64         struct bpf_link *link;                     64         struct bpf_link *link;
 65         __u32 opt;                                 65         __u32 opt;
 66         __u64 ecode;                               66         __u64 ecode;
 67                                                    67 
 68         libbpf_set_print(libbpf_print_fn);         68         libbpf_set_print(libbpf_print_fn);
 69         signal(SIGINT, sigint_handler);            69         signal(SIGINT, sigint_handler);
 70         signal(SIGTERM, sigint_handler);           70         signal(SIGTERM, sigint_handler);
 71 restart:                                           71 restart:
 72         skel = SCX_OPS_OPEN(simple_ops, scx_si     72         skel = SCX_OPS_OPEN(simple_ops, scx_simple);
 73                                                    73 
 74         while ((opt = getopt(argc, argv, "fvh"     74         while ((opt = getopt(argc, argv, "fvh")) != -1) {
 75                 switch (opt) {                     75                 switch (opt) {
 76                 case 'f':                          76                 case 'f':
 77                         skel->rodata->fifo_sch     77                         skel->rodata->fifo_sched = true;
 78                         break;                     78                         break;
 79                 case 'v':                          79                 case 'v':
 80                         verbose = true;            80                         verbose = true;
 81                         break;                     81                         break;
 82                 default:                           82                 default:
 83                         fprintf(stderr, help_f     83                         fprintf(stderr, help_fmt, basename(argv[0]));
 84                         return opt != 'h';         84                         return opt != 'h';
 85                 }                                  85                 }
 86         }                                          86         }
 87                                                    87 
 88         SCX_OPS_LOAD(skel, simple_ops, scx_sim     88         SCX_OPS_LOAD(skel, simple_ops, scx_simple, uei);
 89         link = SCX_OPS_ATTACH(skel, simple_ops     89         link = SCX_OPS_ATTACH(skel, simple_ops, scx_simple);
 90                                                    90 
 91         while (!exit_req && !UEI_EXITED(skel,      91         while (!exit_req && !UEI_EXITED(skel, uei)) {
 92                 __u64 stats[2];                    92                 __u64 stats[2];
 93                                                    93 
 94                 read_stats(skel, stats);           94                 read_stats(skel, stats);
 95                 printf("local=%llu global=%llu     95                 printf("local=%llu global=%llu\n", stats[0], stats[1]);
 96                 fflush(stdout);                    96                 fflush(stdout);
 97                 sleep(1);                          97                 sleep(1);
 98         }                                          98         }
 99                                                    99 
100         bpf_link__destroy(link);                  100         bpf_link__destroy(link);
101         ecode = UEI_REPORT(skel, uei);            101         ecode = UEI_REPORT(skel, uei);
102         scx_simple__destroy(skel);                102         scx_simple__destroy(skel);
103                                                   103 
104         if (UEI_ECODE_RESTART(ecode))             104         if (UEI_ECODE_RESTART(ecode))
105                 goto restart;                     105                 goto restart;
106         return 0;                                 106         return 0;
107 }                                                 107 }
108                                                   108 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php