.\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk .\" .\" .\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH PTHREAD_SETSCHEDPARAM 3 "17 novembre 2008" Linux "Manuel du programmeur Linux" .SH NOM pthread_setschedparam, pthread_getschedparam \- Définir ou obtenir la politique et les paramètres d'ordonnancement d'un thread .SH SYNOPSIS .nf \fB#include \fP \fBpthread_setschedparam(pthread_t \fP\fIthread\fP\fB, int \fP\fIpolicy\fP\fB,\fP \fB const struct sched_param *\fP\fIparam\fP\fB);\fP \fBpthread_getschedparam(pthread_t \fP\fIthread\fP\fB, int *\fP\fIpolicy\fP\fB,\fP \fB struct sched_param *\fP\fIparam\fP\fB);\fP .sp Compilez et effectuez l'édition des liens avec l'option \fI\-pthread\fP. .fi .SH DESCRIPTION La fonction \fBpthread_setschedparam\fP() définit la politique et les paramètres d'ordonnancement du thread \fIthread\fP. .\" FIXME . pthread_setschedparam() places no restriction on the policy, .\" but pthread_attr_setschedpolicy() restricts policy to RR/FIFO/OTHER .\" http://sourceware.org/bugzilla/show_bug.cgi?id=7013 L'argument \fIpolicy\fP spécifie la politique d'ordonnancement pour \fIthread\fP. Les valeurs possibles, ainsi que leur signification, sont décrites dans \fBsched_setscheduler\fP(2). La structure vers laquelle pointe \fIparam\fP spécifie les nouveaux paramètres d'ordonnancement pour \fIthread\fP. Les paramètres d'ordonnancement sont gérés dans la structure suivante\ : .in +4n .nf struct sched_param { int sched_priority; /* Priorité d'ordonnancement */ }; .fi .in Comme on peut le voir, un seul paramètre d'ordonnancement est supporté. Veuillez consulter \fBsched_setscheduler\fP(2) pour plus de détails sur les valeurs possibles des priorités d'ordonnancement en fonction de chaque politique d'ordonnancement. .\" FIXME . nptl/pthread_setschedparam.c has the following .\" /* If the thread should have higher priority because of some .\" PTHREAD_PRIO_PROTECT mutexes it holds, adjust the priority. */ .\" Eventually (perhaps after writing the mutexattr pages), we .\" may want to add something on the topic to this page. La fonction \fBpthread_getschedparam\fP() renvoie, dans les tampons pointés par \fIpolicy\fP et \fIparam\fP, respectivement la politique et les paramètres d'ordonnancement du thread \fIthread\fP. La valeur de priorité renvoyée est celle utilisée lors de l'appel le plus récent à \fBpthread_setschedparam\fP(), \fBpthread_setschedprio\fP(3) ou \fBpthread_create\fP(3) qui touchait \fIthread\fP. La priorité renvoyée ne reflète pas des ajustements de priorité temporaires qui peuvent résulter d'appels à une fonction qui modifie l'héritage ou plafonne la priorité d'ordonnancement (voir, par exemple, \fBpthread_mutexattr_setprioceiling\fP(3) et \fBpthread_mutexattr_setprotocol\fP(3)). .SH "VALEUR RENVOYÉE" En cas de réussite, ces fonctions renvoient 0\ ; en cas d'erreur, elles renvoient un numéro d'erreur non nul. Si \fBpthread_setschedparam\fP() échoue, la politique et les paramètres d'ordonnancement du thread ne sont pas modifiés. .SH ERREURS Ces deux fonctions peuvent échouer avec l'erreur suivante\ : .TP \fBESRCH\fP Aucun thread avec pour identifiant \fIthread\fP n'a pu être trouvé. .PP \fBpthread_setschedparam\fP() peut également échouer avec les erreurs suivantes\ : .TP \fBEINVAL\fP \fIpolicy\fP n'est pas une politique reconnue, ou \fIparam\fP n'a pas de sens pour cette valeur de \fIpolicy\fP. .TP \fBEPERM\fP L'appelant n'a pas les privilèges suffisants pour définir la politique et les paramètres d'ordonnancement indiqués. .PP .\" .SH VERSIONS .\" Available since glibc 2.0 POSIX.1\-2001 documente également une erreur \fBENOTSUP\fP (tentative de définition de la politique ou de paramètres d'ordonnancement à une valeur non prise en charge) pour \fBpthread_setschedparam\fP(). .SH CONFORMITÉ POSIX.1\-2001. .SH NOTES Pour une description des permissions nécessaires pour modifier la politique et la priorité d'ordonnancement d'un thread (et leur effet), et les détails sur les valeurs possibles de priorités pour chacune des politiques d'ordonnancement, consultez \fBsched_setscheduler\fP(2). .SH EXEMPLE Le programme ci\-dessous montre l'utilisation de \fBpthread_setschedparam\fP() et \fBpthread_getschedparam\fP(), ainsi que d'un certain nombre d'autres fonctions de pthreads relatives à l'ordonnancement. Lors de l'exécution suivante, le thread principal définit sa politique d'ordonnancement à \fBSCHED_FIFO\fP avec une priorité de 10, et initialise un objet d'attributs de thread avec un attribut de politique d'ordonnancement mis à \fBSCHED_RR\fP, et un attribut de priorité d'ordonnancement de 20. Le programme appelle alors \fBpthread_attr_setinheritsched\fP(3) pour définir à \fBPTHREAD_EXPLICIT_SCHED\fP l'attribut d'héritage de l'ordonnancement de l'objets d'attributs de thread, ce qui signifie que les threads créés avec cet objet d'attributs prendront les attributs d'ordonnancement dans l'objet d'attributs de thread. Le programme crée alors un thread en utilisant l'objets d'attributs de thread, et ce thread affiche sa politique et sa priorité d'ordonnancement. .in +4n .nf $ \fBsu\fP # Need privilege to set real\-time scheduling policies Password: # \fB./a.out \-mf10 \-ar20 \-i e\fP Scheduler settings of main thread policy=SCHED_FIFO, priority=10 Scheduler settings in \(aqattr\(aq policy=SCHED_RR, priority=20 inheritsched is EXPLICIT Scheduler attributes of new thread policy=SCHED_RR, priority=20 .fi .in Nous pouvons voir dans l'affichage ci\-dessus que les politique et priorité d'ordonnancement ont pris comme valeurs celles de l'objets d'attributs de thread. L'exécution suivante est identique, sauf que l'attribut d'héritage d'ordonnancement est mis à \fBPTHREAD_INHERIT_SCHED\fP, ce qui signifie que les threads créés avec cet objet d'attributs devront ignorer les attributs d'ordonnancement de l'objets d'attributs de thread, et prendre à la place les valeurs héritées du thread appelant. .in +4n .nf # \fB./a.out \-mf10 \-ar20 \-i i\fP Scheduler settings of main thread policy=SCHED_FIFO, priority=10 Scheduler settings in \(aqattr\(aq policy=SCHED_RR, priority=20 inheritsched is INHERIT Scheduler attributes of new thread policy=SCHED_FIFO, priority=10 .fi .in Nous pouvons voir dans l'affichage ci\-dessus que les politique et priorité d'ordonnancement ont pris comme valeurs celles du thread appelant, et non de l'objets d'attributs de thread. Veuillez noter que si l'option \fI\-i\ i\fP n'avait pas été présente, l'affichage aurait été identique, car \fBPTHREAD_INHERIT_SCHED\fP est la valeur par défaut pour l'attribut d'héritage d'ordonnancement. .SS "Source du programme" \& .nf /* pthreads_sched_test.c */ #include #include #include #include #include #define handle_error_en(en, msg) \e do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0) static void usage(char *prog_name, char *msg) { if (msg != NULL) fputs(msg, stderr); fprintf(stderr, "Usage: %s [options]\en", prog_name); fprintf(stderr, "Options are:\en"); #define fpe(msg) fprintf(stderr, "\et%s", msg); /* Shorter */ fpe("\-a Set scheduling policy and priority in\en"); fpe(" thread attributes object\en"); fpe(" can be\en"); fpe(" f SCHED_FIFO\en"); fpe(" r SCHED_RR\en"); fpe(" o SCHED_OTHER\en"); fpe("\-A Use default thread attributes object\en"); fpe("\-i {e|s} Set inherit scheduler attribute to\en"); fpe(" \(aqexplicit\(aq or \(aqinherit\(aq\en"); fpe("\-m Set scheduling policy and priority on\en"); fpe(" main thread before pthread_create() call\en"); exit(EXIT_FAILURE); } static int get_policy(char p, int *policy) { switch (p) { case \(aqf\(aq: *policy = SCHED_FIFO; return 1; case \(aqr\(aq: *policy = SCHED_RR; return 1; case \(aqo\(aq: *policy = SCHED_OTHER; return 1; default: return 0; } } static void display_sched_attr(int policy, struct sched_param *param) { printf(" policy=%s, priority=%d\en", (policy == SCHED_FIFO) ? "SCHED_FIFO" : (policy == SCHED_RR) ? "SCHED_RR" : (policy == SCHED_OTHER) ? "SCHED_OTHER" : "???", param\->sched_priority); } static void display_thread_sched_attr(char *msg) { int policy, s; struct sched_param param; s = pthread_getschedparam(pthread_self(), &policy, ¶m); if (s != 0) handle_error_en(s, "pthread_getschedparam"); printf("%s\en", msg); display_sched_attr(policy, ¶m); } static void * thread_start(void *arg) { display_thread_sched_attr("Scheduler attributes of new thread"); return NULL; } int main(int argc, char *argv[]) { int s, opt, inheritsched, use_null_attrib, policy; pthread_t thread; pthread_attr_t attr; pthread_attr_t *attrp; char *attr_sched_str, *main_sched_str, *inheritsched_str; struct sched_param param; /* Process command\-line options */ use_null_attrib = 0; attr_sched_str = NULL; main_sched_str = NULL; inheritsched_str = NULL; while ((opt = getopt(argc, argv, "a:Ai:m:")) != \-1) { switch (opt) { case \(aqa\(aq: attr_sched_str = optarg; break; case \(aqA\(aq: use_null_attrib = 1; break; case \(aqi\(aq: inheritsched_str = optarg; break; case \(aqm\(aq: main_sched_str = optarg; break; default: usage(argv[0], "Unrecognized option\en"); } } if (use_null_attrib && (inheritsched_str != NULL || attr_sched_str != NULL)) usage(argv[0], "Can\(aqt specify \-A with \-i or \-a\en"); /* Optionally set scheduling attributes of main thread, and display the attributes */ if (main_sched_str != NULL) { if (!get_policy(main_sched_str[0], &policy)) usage(argv[0], "Bad policy for main thread (\-s)\en"); param.sched_priority = strtol(&main_sched_str[1], NULL, 0); s = pthread_setschedparam(pthread_self(), policy, ¶m); if (s != 0) handle_error_en(s, "pthread_setschedparam"); } display_thread_sched_attr("Scheduler settings of main thread"); printf("\en"); /* Initialize thread attributes object according to options */ attrp = NULL; if (!use_null_attrib) { s = pthread_attr_init(&attr); if (s != 0) handle_error_en(s, "pthread_attr_init"); attrp = &attr; } if (inheritsched_str != NULL) { if (inheritsched_str[0] == \(aqe\(aq) inheritsched = PTHREAD_EXPLICIT_SCHED; else if (inheritsched_str[0] == \(aqi\(aq) inheritsched = PTHREAD_INHERIT_SCHED; else usage(argv[0], "Value for \-i must be \(aqe\(aq or \(aqi\(aq\en"); s = pthread_attr_setinheritsched(&attr, inheritsched); if (s != 0) handle_error_en(s, "pthread_attr_setinheritsched"); } if (attr_sched_str != NULL) { if (!get_policy(attr_sched_str[0], &policy)) usage(argv[0], "Bad policy for \(aqattr\(aq (\-a)\en"); param.sched_priority = strtol(&attr_sched_str[1], NULL, 0); s = pthread_attr_setschedpolicy(&attr, policy); if (s != 0) handle_error_en(s, "pthread_attr_setschedpolicy"); s = pthread_attr_setschedparam(&attr, ¶m); if (s != 0) handle_error_en(s, "pthread_attr_setschedparam"); } /* If we initialized a thread attributes object, display the scheduling attributes that were set in the object */ if (attrp != NULL) { s = pthread_attr_getschedparam(&attr, ¶m); if (s != 0) handle_error_en(s, "pthread_attr_getschedparam"); s = pthread_attr_getschedpolicy(&attr, &policy); if (s != 0) handle_error_en(s, "pthread_attr_getschedpolicy"); printf("Scheduler settings in \(aqattr\(aq\en"); display_sched_attr(policy, ¶m); s = pthread_attr_getinheritsched(&attr, &inheritsched); printf(" inheritsched is %s\en", (inheritsched == PTHREAD_INHERIT_SCHED) ? "INHERIT" : (inheritsched == PTHREAD_EXPLICIT_SCHED) ? "EXPLICIT" : "???"); printf("\en"); } /* Create a thread that will display its scheduling attributes */ s = pthread_create(&thread, attrp, &thread_start, NULL); if (s != 0) handle_error_en(s, "pthread_create"); /* Destroy unneeded thread attributes object */ s = pthread_attr_destroy(&attr); if (s != 0) handle_error_en(s, "pthread_attr_destroy"); s = pthread_join(thread, NULL); if (s != 0) handle_error_en(s, "pthread_join"); exit(EXIT_SUCCESS); } .fi .SH "VOIR AUSSI" .ad l .nh \fBgetrlimit\fP(2), \fBsched_get_priority_min\fP(2), \fBsched_setscheduler\fP(2), \fBpthread_attr_init\fP(3), \fBpthread_attr_setinheritsched\fP(3), \fBpthread_attr_setschedparam\fP(3), \fBpthread_attr_setschedpolicy\fP(3), \fBpthread_create\fP(3), \fBpthread_self\fP(3), \fBpthread_setschedprio\fP(3), \fBpthreads\fP(7) .SH COLOPHON Cette page fait partie de la publication 3.65 du projet \fIman\-pages\fP Linux. Une description du projet et des instructions pour signaler des anomalies peuvent être trouvées à l'adresse \%http://www.kernel.org/doc/man\-pages/. .SH TRADUCTION Depuis 2010, cette traduction est maintenue à l'aide de l'outil po4a par l'équipe de traduction francophone au sein du projet perkamon . .PP Denis Barbier (2010). .PP Veuillez signaler toute erreur de traduction en écrivant à ou par un rapport de bogue sur le paquet \fBmanpages\-fr\fR. .PP Vous pouvez toujours avoir accès à la version anglaise de ce document en utilisant la commande «\ \fBman\ \-L C\fR \fI
\fR\ \fI\fR\ ».