/* *parse_cpu_set-parseacpu_listfillingcpu_set_targument * *Receivesacpulist,like1-3,5(cpus1,2,3,5),andthenset *fillingcpu_set_targument. * *Returns1onsuccess,0otherwise.
*/ int parse_cpu_set(char *cpu_list, cpu_set_t *set)
{ constchar *p; int end_cpu; int nr_cpus; int cpu; int i;
CPU_ZERO(set);
nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
for (p = cpu_list; *p; ) {
cpu = atoi(p); if (cpu < 0 || (!cpu && *p != '0') || cpu >= nr_cpus) goto err;
while (isdigit(*p))
p++; if (*p == '-') {
p++;
end_cpu = atoi(p); if (end_cpu < cpu || (!end_cpu && *p != '0') || end_cpu >= nr_cpus) goto err; while (isdigit(*p))
p++;
} else
end_cpu = cpu;
if (cpu == end_cpu) {
debug_msg("cpu_set: adding cpu %d\n", cpu);
CPU_SET(cpu, set);
} else { for (i = cpu; i <= end_cpu; i++) {
debug_msg("cpu_set: adding cpu %d\n", i);
CPU_SET(i, set);
}
}
if (*p == ',')
p++;
}
return0;
err:
debug_msg("Error parsing the cpu set %s\n", cpu_list); return1;
}
/* *parse_duration-parsedurationwiths/m/h/dsuffixconvertingittoseconds
*/ long parse_seconds_duration(char *val)
{ char *end; long t;
t = strtol(val, &end, 10);
if (end) { switch (*end) { case's': case'S': break; case'm': case'M':
t *= 60; break; case'h': case'H':
t *= 60 * 60; break;
case'd': case'D':
t *= 24 * 60 * 60; break;
}
}
return t;
}
/* *parse_ns_duration-parsedurationwithns/us/ms/sconvertingittonanoseconds
*/ long parse_ns_duration(char *val)
{ char *end; long t;
int __set_sched_attr(int pid, struct sched_attr *attr)
{ int flags = 0; int retval;
retval = syscall_sched_setattr(pid, attr, flags); if (retval < 0) {
err_msg("Failed to set sched attributes to the pid %d: %s\n",
pid, strerror(errno)); return1;
}
retval = strncmp(comm_prefix, buffer, strlen(comm_prefix)); if (retval) return0;
/* comm already have \n */
debug_msg("Found workload pid:%s comm:%s", proc_entry->d_name, buffer);
return1;
}
/* *set_comm_sched_attr-setschedparamstothreadsstartingwithchar*comm_prefix * *Thisfunctionusesprocfstolistthecurrentlyrunningthreadsandthensetthe *sched_attr*attrtothethreadsthatstartwithchar*comm_prefix.Itis *mainlyusedtosettheprioritytothekernelthreadscreatedbythe *tracers.
*/ int set_comm_sched_attr(constchar *comm_prefix, struct sched_attr *attr)
{ struct dirent *proc_entry;
DIR *procfs; int retval;
if (strlen(comm_prefix) >= MAX_PATH) {
err_msg("Command prefix is too long: %d < strlen(%s)\n",
MAX_PATH, comm_prefix); return1;
}
procfs = opendir("/proc"); if (!procfs) {
err_msg("Could not open procfs\n"); return1;
}
while ((proc_entry = readdir(procfs))) {
retval = procfs_is_workload_pid(comm_prefix, proc_entry); if (!retval) continue;
/* procfs_is_workload_pid confirmed it is a pid */
retval = __set_sched_attr(atoi(proc_entry->d_name), attr); if (retval) {
err_msg("Error setting sched attributes for pid:%s\n", proc_entry->d_name); goto out_err;
}
debug_msg("Set sched attributes for pid:%s\n", proc_entry->d_name);
} return0;
out_err:
closedir(procfs); return1;
}
#define INVALID_VAL (~0L) staticlong get_long_ns_after_colon(char *start)
{ long val = INVALID_VAL;
/* find the ":" */
start = strstr(start, ":"); if (!start) return -1;
/* skip ":" */
start++;
val = parse_ns_duration(start);
return val;
}
staticlong get_long_after_colon(char *start)
{ long val = INVALID_VAL;
/* find the ":" */
start = strstr(start, ":"); if (!start) return -1;
/* skip ":" */
start++;
val = get_llong_from_str(start);
return val;
}
/* *parsepriorityintheformat: *SCHED_OTHER: *o:<prio> *O:<prio> *SCHED_RR: *r:<prio> *R:<prio> *SCHED_FIFO: *f:<prio> *F:<prio> *SCHED_DEADLINE: *d:runtime:period *D:runtime:period
*/ int parse_prio(char *arg, struct sched_attr *sched_param)
{ long prio; long runtime; long period;
/** *auto_house_keeping-Automaticallymovertlaoutofmeasurementthreads * *Trytomovertlaawayfromthetracer,ifpossible. * *Returns1onsuccess,0otherwise.
*/ int auto_house_keeping(cpu_set_t *monitored_cpus)
{
cpu_set_t rtla_cpus, house_keeping_cpus; int retval;
/* first get the CPUs in which rtla can actually run. */
retval = sched_getaffinity(getpid(), sizeof(rtla_cpus), &rtla_cpus); if (retval == -1) {
debug_msg("Could not get rtla affinity, rtla might run with the threads!\n"); return0;
}
/* then check if the existing setup is already good. */
CPU_AND(&house_keeping_cpus, &rtla_cpus, monitored_cpus); if (!CPU_COUNT(&house_keeping_cpus)) {
debug_msg("rtla and the monitored CPUs do not share CPUs.");
debug_msg("Skipping auto house-keeping\n"); return1;
}
/* remove the intersection */
CPU_XOR(&house_keeping_cpus, &rtla_cpus, monitored_cpus);
/* get only those that rtla can run */
CPU_AND(&house_keeping_cpus, &house_keeping_cpus, &rtla_cpus);
/* is there any cpu left? */ if (!CPU_COUNT(&house_keeping_cpus)) {
debug_msg("Could not find any CPU for auto house-keeping\n"); return0;
}
retval = sched_setaffinity(getpid(), sizeof(house_keeping_cpus), &house_keeping_cpus); if (retval == -1) {
debug_msg("Could not set affinity for auto house-keeping\n"); return0;
}
debug_msg("rtla automatically moved to an auto house-keeping cpu set\n");
return1;
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet am 2026-10-02)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.