1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include <linux/bpf.h> 18 #include <stdbool.h> 19 #include <stdint.h> 20 #include <bpf_helpers.h> 21 22 /* Assume max of 1024 CPUs */ 23 DEFINE_BPF_MAP(cpu_pid_map, ARRAY, int, uint32_t, 1024) 24 25 struct switch_args { 26 unsigned long long ignore; 27 char prev_comm[16]; 28 int prev_pid; 29 int prev_prio; 30 long long prev_state; 31 char next_comm[16]; 32 int next_pid; 33 int next_prio; 34 }; 35 36 DEFINE_BPF_PROG("tracepoint/sched/sched_switch", AID_ROOT, AID_ROOT, tp_sched_switch) 37 (struct switch_args* args) { 38 int key; 39 uint32_t val; 40 41 key = bpf_get_smp_processor_id(); 42 val = args->next_pid; 43 44 bpf_cpu_pid_map_update_elem(&key, &val, BPF_ANY); 45 return 0; 46 } 47 48 49 struct wakeup_args { 50 unsigned long long ignore; 51 char comm[16]; 52 int pid; 53 int prio; 54 int success; 55 int target_cpu; 56 }; 57 58 DEFINE_BPF_PROG_KVER("tracepoint/sched/sched_wakeup", AID_ROOT, AID_ROOT, tp_sched_wakeup, KVER_INF) 59 (struct wakeup_args* __unused args) { 60 return 0; 61 } 62 63 LICENSE("GPL"); 64