// SPDX-License-Identifier: GPL-2.0-only /* * Use the core scheduling prctl() to test core scheduling cookies control. * * Copyright (c) 2021 Oracle and/or its affiliates. * Author: Chris Hyser <chris.hyser@oracle.com> * * * This library is free software; you can redistribute it and/or modify it * under the terms of version 2.1 of the GNU Lesser General Public License as * published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, see <http://www.gnu.org/licenses>.
*/
staticconstchar USAGE[] = "cs_prctl_test [options]\n" " options:\n" " -P : number of processes to create.\n" " -T : number of threads per process to create.\n" " -d : delay time to keep tasks alive.\n" " -k : keep tasks alive until keypress.\n";
for (i = 0; i < num_processes; ++i) {
ret = read(proc[i].pfd[0], &proc[i].thr_tids, sizeof(int) * proc[i].num_threads); if (ret == -1)
printf("read failed on proc[%d].pfd[0] error (%s)\n",
i, strerror(errno));
close(proc[i].pfd[0]);
}
}
void disp_processes(int num_processes, struct child_args proc[])
{ int i, j;
/* put into separate process group */ if (setpgid(0, 0) != 0)
handle_error("process group");
printf("\n## Create a thread/process/process group hierarchy\n");
create_processes(num_processes, num_threads, procs);
need_cleanup = 1;
disp_processes(num_processes, procs);
validate(get_cs_cookie(0) == 0);
printf("\n## Set a cookie on entire process group\n"); if (_prctl(PR_SCHED_CORE, PR_SCHED_CORE_CREATE, 0, PIDTYPE_PGID, 0) < 0)
handle_error("core_sched create failed -- PGID");
disp_processes(num_processes, procs);
validate(get_cs_cookie(0) != 0);
/* get a random process pid */
pidx = rand() % num_processes;
pid = procs[pidx].cpid;
printf("\n## Set a new cookie on entire process/TGID [%d]\n", pid); if (_prctl(PR_SCHED_CORE, PR_SCHED_CORE_CREATE, pid, PIDTYPE_TGID, 0) < 0)
handle_error("core_sched create failed -- TGID");
disp_processes(num_processes, procs);
printf("\n## Copy the cookie of current/PGID[%d], to pid [%d] as PIDTYPE_PID\n",
getpid(), pid); if (_prctl(PR_SCHED_CORE, PR_SCHED_CORE_SHARE_TO, pid, PIDTYPE_PID, 0) < 0)
handle_error("core_sched share to itself failed -- PID");
disp_processes(num_processes, procs);
printf("\n## Copy cookie from current [%d] to current as pidtype PGID\n", getpid()); if (_prctl(PR_SCHED_CORE, PR_SCHED_CORE_SHARE_TO, 0, PIDTYPE_PGID, 0) < 0)
handle_error("core_sched share to self failed -- PGID");
disp_processes(num_processes, procs);
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.