From: Loic Domaigne <tech-Z4JMKDdsf89Wk0Htik3J/w@public.gmane.org>
To: Michael Kerrisk <mtk.manpages-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>
Cc: linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
josv-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org,
"brian m. carlson"
<sandals-spVehEqlxw627WubY2PhZQivdfXVPZ6z@public.gmane.org>,
Bert Wesarg <bert.wesarg-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>,
Stefan Puiu
<stefanpuiuro-/E1597aS9LQAvxtiuMwx3w@public.gmane.org>,
Karsten Weiss
<K.Weiss-Pt+Xe7GJXK+P2YhJcF5u+nqWYbMAw+HU@public.gmane.org>
Subject: sched_setscheduler.3 and threads (was: For review: pthread_setschedparam.3)
Date: Mon, 24 Nov 2008 22:09:37 +0100 [thread overview]
Message-ID: <492B1811.3080001@domaigne.com> (raw)
In-Reply-To: <4922C81F.6070907-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Hello Michael,
I've investigated the effects of sched_setscheduler() on threads. Things
seem worse than I expected.
AFAICS, you can change scheduling attribute of a thread using
sched_setscheduler(3) without the changes being reflected in the
thread's scheduling parameters as retrieved with pthread_getschedparam(3).
Output from the schedtest program below:
<copy>
main > call sched_setscheduler(0,FIFO,1)
main > pthread_getschedparam() : Policy=FIFO, prio=1
main > sched_getscheduler() : Policy=FIFO, prio=1
-----
Thread > pthread_getschedparam() : Policy=*NOT* FIFO, prio=0
Thread > sched_getscheduler() : Policy=*NOT* FIFO, prio=0
-----
Thread > call sched_setscheduler(0,FIFO,2)
Thread > pthread_getschedparam() : Policy=*NOT* FIFO, prio=0
Thread > sched_getscheduler() : Policy=FIFO, prio=2
-----
main > pthread_getschedparam() : Policy=FIFO, prio=1
main > sched_getscheduler() : Policy=FIFO, prio=1
-----
</copy>
Let's hope that my program is broken!
A+,
Loïc
--
/***************************************************************************/
/* schedtest.c- test interaction between sched_setscheduler and threads
/***************************************************************************/
/*
* compile with: cc -pthread schedtest.c -o schedtest
*/
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
/**********************************************************************/
/* our macro for errors checking */
/**********************************************************************/
#define COND_CHECK(func, cond, errv) \
if ( (cond) ) \
{ \
fprintf(stderr, "\n[CHECK FAILED at %s:%d]\n| %s(...)=%d (%s)\n\n",\
__FILE__,__LINE__,func,errv,strerror(errv)); \
exit(EXIT_FAILURE); \
}
#define UnixCheck(func,rc) COND_CHECK(func, (rc==-1), errno)
#define PthreadCheck(func,rc) COND_CHECK(func,(rc!=0), rc)
void
sched_fifo(const char* thr, int prio)
{
struct sched_param param;
int rc;
printf("%s > call sched_setscheduler(0,FIFO,%d)\n", thr, prio);
param.sched_priority = prio;
rc = sched_setscheduler(0, SCHED_FIFO, ¶m);
UnixCheck("sched_setscheduler", rc);
}
void
sched_info(const char* thr)
{
struct sched_param param;
int policy;
int rc;
rc = pthread_getschedparam(pthread_self(), &policy, ¶m);
PthreadCheck("pthread_getschedparam", rc);
printf("%s > pthread_getschedparam() : Policy=%s, prio=%d\n",
thr,
(policy==SCHED_FIFO) ? "FIFO" : "*NOT* FIFO",
param.sched_priority);
policy = sched_getscheduler(0);
UnixCheck("sched_getscheduler", policy);
rc = sched_getparam(0, ¶m);
UnixCheck("sched_getparam", rc);
printf("%s > sched_getscheduler() : Policy=%s, prio=%d\n",
thr,
(policy==SCHED_FIFO) ? "FIFO" : "*NOT* FIFO",
param.sched_priority);
printf("-----\n");
}
void*
thread(void* ignore)
{
sleep(2);
sched_info("Thread");
sched_fifo("Thread", 2);
sched_info("Thread");
return NULL;
}
int
main()
{
pthread_t tid;
int rc;
rc = pthread_create(&tid, NULL, thread, NULL);
PthreadCheck("pthread_create", rc);
sched_fifo("main ", 1);
sched_info("main ");
rc = pthread_join(tid, NULL);
PthreadCheck("pthread_join", rc);
sched_info("main ");
return EXIT_SUCCESS;
}
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
prev parent reply other threads:[~2008-11-24 21:09 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-06 17:45 For review: pthread_setschedparam.3 Michael Kerrisk
[not found] ` <cfd18e0f0811060945n3224567du5e98adecb074b5e-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-11-15 21:09 ` Loic Domaigne
[not found] ` <491F3AA6.6050303-Z4JMKDdsf89Wk0Htik3J/w@public.gmane.org>
2008-11-17 18:23 ` Michael Kerrisk
[not found] ` <cfd18e0f0811171023l38ae6a0ci1bbece2dcc9e441d-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-11-17 19:22 ` Loic Domaigne
[not found] ` <4921C470.5070807-Z4JMKDdsf89Wk0Htik3J/w@public.gmane.org>
2008-11-18 12:04 ` Michael Kerrisk
2008-11-18 13:50 ` Michael Kerrisk
[not found] ` <4922C81F.6070907-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2008-11-21 19:06 ` Loic Domaigne
2008-11-24 21:09 ` Loic Domaigne [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=492B1811.3080001@domaigne.com \
--to=tech-z4jmkddsf89wk0htik3j/w@public.gmane.org \
--cc=K.Weiss-Pt+Xe7GJXK+P2YhJcF5u+nqWYbMAw+HU@public.gmane.org \
--cc=bert.wesarg-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org \
--cc=josv-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
--cc=linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=mtk.manpages-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org \
--cc=sandals-spVehEqlxw627WubY2PhZQivdfXVPZ6z@public.gmane.org \
--cc=stefanpuiuro-/E1597aS9LQAvxtiuMwx3w@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.