| Joel Fernandes | 482dfa1 | 2018-11-27 18:09:19 -0800 | [diff] [blame] | 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> |
| Joel Fernandes (Google) | 4134dbb | 2019-02-12 12:47:25 -0500 | [diff] [blame^] | 20 | #include <bpf_helpers.h> |
| Joel Fernandes | 482dfa1 | 2018-11-27 18:09:19 -0800 | [diff] [blame] | 21 | |
| 22 | struct bpf_map_def SEC("maps") cpu_pid = { |
| 23 | .type = BPF_MAP_TYPE_ARRAY, |
| 24 | .key_size = sizeof(int), |
| 25 | .value_size = sizeof(uint32_t), |
| 26 | /* Assume max of 1024 CPUs */ |
| 27 | .max_entries = 1024, |
| 28 | }; |
| 29 | |
| 30 | struct switch_args { |
| 31 | unsigned long long ignore; |
| 32 | char prev_comm[16]; |
| 33 | int prev_pid; |
| 34 | int prev_prio; |
| 35 | long long prev_state; |
| 36 | char next_comm[16]; |
| 37 | int next_pid; |
| 38 | int next_prio; |
| 39 | }; |
| 40 | |
| 41 | SEC("tracepoint/sched/sched_switch") |
| 42 | int tp_sched_switch(struct switch_args* args) { |
| 43 | int key; |
| 44 | uint32_t val; |
| 45 | |
| 46 | key = bpf_get_smp_processor_id(); |
| 47 | val = args->next_pid; |
| 48 | |
| 49 | bpf_map_update_elem(&cpu_pid, &key, &val, BPF_ANY); |
| 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | char _license[] SEC("license") = "GPL"; |