Namhyung Kim | 12864b3 | 2012-04-26 14:15:22 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Helper functions for handling target threads/cpus |
| 3 | * |
| 4 | * Copyright (C) 2012, LG Electronics, Namhyung Kim <namhyung.kim@lge.com> |
| 5 | * |
| 6 | * Released under the GPL v2. |
| 7 | */ |
| 8 | |
| 9 | #include "target.h" |
| 10 | #include "debug.h" |
| 11 | |
| 12 | |
Namhyung Kim | 60bbdda | 2012-05-07 14:09:00 +0900 | [diff] [blame^] | 13 | enum perf_target_errno perf_target__validate(struct perf_target *target) |
Namhyung Kim | 12864b3 | 2012-04-26 14:15:22 +0900 | [diff] [blame] | 14 | { |
Namhyung Kim | 60bbdda | 2012-05-07 14:09:00 +0900 | [diff] [blame^] | 15 | enum perf_target_errno ret = PERF_ERRNO_TARGET__SUCCESS; |
| 16 | |
Namhyung Kim | 12864b3 | 2012-04-26 14:15:22 +0900 | [diff] [blame] | 17 | if (target->pid) |
| 18 | target->tid = target->pid; |
| 19 | |
| 20 | /* CPU and PID are mutually exclusive */ |
| 21 | if (target->tid && target->cpu_list) { |
Namhyung Kim | 12864b3 | 2012-04-26 14:15:22 +0900 | [diff] [blame] | 22 | target->cpu_list = NULL; |
Namhyung Kim | 60bbdda | 2012-05-07 14:09:00 +0900 | [diff] [blame^] | 23 | if (ret == PERF_ERRNO_TARGET__SUCCESS) |
| 24 | ret = PERF_ERRNO_TARGET__PID_OVERRIDE_CPU; |
Namhyung Kim | 12864b3 | 2012-04-26 14:15:22 +0900 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | /* UID and PID are mutually exclusive */ |
| 28 | if (target->tid && target->uid_str) { |
Namhyung Kim | 12864b3 | 2012-04-26 14:15:22 +0900 | [diff] [blame] | 29 | target->uid_str = NULL; |
Namhyung Kim | 60bbdda | 2012-05-07 14:09:00 +0900 | [diff] [blame^] | 30 | if (ret == PERF_ERRNO_TARGET__SUCCESS) |
| 31 | ret = PERF_ERRNO_TARGET__PID_OVERRIDE_UID; |
Namhyung Kim | 12864b3 | 2012-04-26 14:15:22 +0900 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | /* UID and CPU are mutually exclusive */ |
| 35 | if (target->uid_str && target->cpu_list) { |
Namhyung Kim | 12864b3 | 2012-04-26 14:15:22 +0900 | [diff] [blame] | 36 | target->cpu_list = NULL; |
Namhyung Kim | 60bbdda | 2012-05-07 14:09:00 +0900 | [diff] [blame^] | 37 | if (ret == PERF_ERRNO_TARGET__SUCCESS) |
| 38 | ret = PERF_ERRNO_TARGET__UID_OVERRIDE_CPU; |
Namhyung Kim | 12864b3 | 2012-04-26 14:15:22 +0900 | [diff] [blame] | 39 | } |
| 40 | |
Namhyung Kim | 60bbdda | 2012-05-07 14:09:00 +0900 | [diff] [blame^] | 41 | /* PID and SYSTEM are mutually exclusive */ |
| 42 | if (target->tid && target->system_wide) { |
Namhyung Kim | 12864b3 | 2012-04-26 14:15:22 +0900 | [diff] [blame] | 43 | target->system_wide = false; |
Namhyung Kim | 60bbdda | 2012-05-07 14:09:00 +0900 | [diff] [blame^] | 44 | if (ret == PERF_ERRNO_TARGET__SUCCESS) |
| 45 | ret = PERF_ERRNO_TARGET__PID_OVERRIDE_SYSTEM; |
Namhyung Kim | 12864b3 | 2012-04-26 14:15:22 +0900 | [diff] [blame] | 46 | } |
Namhyung Kim | 60bbdda | 2012-05-07 14:09:00 +0900 | [diff] [blame^] | 47 | |
| 48 | /* UID and SYSTEM are mutually exclusive */ |
| 49 | if (target->uid_str && target->system_wide) { |
| 50 | target->system_wide = false; |
| 51 | if (ret == PERF_ERRNO_TARGET__SUCCESS) |
| 52 | ret = PERF_ERRNO_TARGET__UID_OVERRIDE_SYSTEM; |
| 53 | } |
| 54 | |
| 55 | return ret; |
Namhyung Kim | 12864b3 | 2012-04-26 14:15:22 +0900 | [diff] [blame] | 56 | } |