AP_HAL_Linux: small fixes to cpu affinity

- Do not mention x:y form in the comment since it's not supported
  - Give more detail in the help output regarding the meaning of each form
  - No prints in the helper parse function, let the caller print it
This commit is contained in:
Lucas De Marchi 2021-10-08 13:40:49 -07:00 committed by Lucas De Marchi
parent 9f1cbdc0a5
commit 24adf18685
3 changed files with 7 additions and 8 deletions

View File

@ -297,8 +297,9 @@ void _usage(void)
printf("\t --module-directory %s\n", AP_MODULE_DEFAULT_DIRECTORY);
printf("\t -M %s\n", AP_MODULE_DEFAULT_DIRECTORY);
#endif
printf("\tcpu affinity --cpu-affinity 0,3 or 0,3\n");
printf("\t -c 0,3 or range -c 1,3\n");
printf("\tcpu affinity:\n");
printf("\t --cpu-affinity 1 (single cpu) or 1,3 (multiple cpus) or 1-3 (range of cpus)\n");
printf("\t -c 1 (single cpu) or 1,3 (multiple cpus) or 1-3 (range of cpus)\n");
}
void HAL_Linux::run(int argc, char* const argv[], Callbacks* callbacks) const
@ -383,6 +384,7 @@ void HAL_Linux::run(int argc, char* const argv[], Callbacks* callbacks) const
case 'c':
cpu_set_t cpu_affinity;
if (!utilInstance.parse_cpu_set(gopt.optarg, &cpu_affinity)) {
fprintf(stderr, "Could not parse cpu affinity: %s\n", gopt.optarg);
exit(1);
}
Linux::Scheduler::from(scheduler)->set_cpu_affinity(cpu_affinity);

View File

@ -316,7 +316,6 @@ bool Util::parse_cpu_set(const char *str, cpu_set_t *cpu_set) const
do {
cpu1 = strtoul(str, &endptr, 10);
if (str == endptr) {
fprintf(stderr, "Invalid option for cpu-affinity: %s missing cpu number\n", str);
return false;
}
@ -328,13 +327,11 @@ bool Util::parse_cpu_set(const char *str, cpu_set_t *cpu_set) const
}
if (sep != '-') {
fprintf(stderr, "Invalid option for cpu-affinity: %s did you means separator - e.g. 1-3\n", str);
return false;
}
cpu2 = strtoul(str, &endptr, 10);
if (str == endptr) {
fprintf(stderr, "Invalid option for cpu-affinity: %s missing end cpu number\n", str);
return false;
}

View File

@ -58,7 +58,7 @@ public:
return custom_defaults;
}
/* Parse cpu set in the form 0,2 or 0-2 or 0:2*/
/* Parse cpu set in the form 0; 0,2; or 0-2 */
bool parse_cpu_set(const char *s, cpu_set_t *cpu_set) const;
bool is_chardev_node(const char *path);