* [PATCH 0/5] *** Add new priority inversion test, plus lib changes *** @ 2009-12-23 16:02 John Kacur 2009-12-23 16:02 ` [PATCH 1/5] rt-tests: Add error routines to the library John Kacur 0 siblings, 1 reply; 8+ messages in thread From: John Kacur @ 2009-12-23 16:02 UTC (permalink / raw) To: Clark Williams, Carsten Emde; +Cc: John Kacur, rt-users, Thomas Gleixner These patches add a new priority inversion test (pip) similar to pi_stress The difference is, that pi_stress uses pthreads and pip uses processes. In addition there are changes to put the headers files in src/include and to add some common error handling routines to our library. Clark: You can pull these patches from git://git.kernel.org/pub/scm/linux/kernel/git/jkacur/rt-tests.git branch: rt-tests-dev-new Thank You John Kacur (5): rt-tests: Add error routines to the library rt-tests: Add a new test pip - priority inheritance with processes rt-tests: Move header files from src/lib to src/include rt-tests: pip - Use check_privs() from the rt-utils library. rt-tests: Add a "make tags" option. .gitignore | 2 +- Makefile | 12 ++- src/include/error.h | 15 ++ src/include/pip.h | 41 ++++++ src/include/rt-get_cpu.h | 46 ++++++ src/include/rt-utils.h | 11 ++ src/lib/error.c | 49 +++++++ src/lib/rt-get_cpu.h | 46 ------ src/lib/rt-utils.h | 11 -- src/pi_tests/pip.c | 347 ++++++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 520 insertions(+), 60 deletions(-) create mode 100644 src/include/error.h create mode 100644 src/include/pip.h create mode 100644 src/include/rt-get_cpu.h create mode 100644 src/include/rt-utils.h create mode 100644 src/lib/error.c delete mode 100644 src/lib/rt-get_cpu.h delete mode 100644 src/lib/rt-utils.h create mode 100644 src/pi_tests/pip.c ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/5] rt-tests: Add error routines to the library 2009-12-23 16:02 [PATCH 0/5] *** Add new priority inversion test, plus lib changes *** John Kacur @ 2009-12-23 16:02 ` John Kacur 2009-12-23 16:02 ` [PATCH 2/5] rt-tests: Add a new test pip - priority inheritance with processes John Kacur 0 siblings, 1 reply; 8+ messages in thread From: John Kacur @ 2009-12-23 16:02 UTC (permalink / raw) To: Clark Williams, Carsten Emde; +Cc: John Kacur, rt-users, Thomas Gleixner Add error routines, similar to those found in Advanced Programming in the UNIX Environment 2nd ed. for use by all rt test programs Signed-off-by: John Kacur <jkacur@redhat.com> --- src/lib/error.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ src/lib/error.h | 14 ++++++++++++++ 2 files changed, 63 insertions(+), 0 deletions(-) create mode 100644 src/lib/error.c create mode 100644 src/lib/error.h diff --git a/src/lib/error.c b/src/lib/error.c new file mode 100644 index 0000000..d5ad2aa --- /dev/null +++ b/src/lib/error.c @@ -0,0 +1,49 @@ +#include "error.h" + +/* Print an error message, plus a message for err and exit with error err */ +void err_exit(int err, char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + err_doit(err, fmt, ap); + va_end(ap); + exit(err); +} + +/* print an error message and return */ +void err_msg(char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + err_doit(0, fmt, ap); + va_end(ap); + return; +} + +/* Print an error message, plus a message for err, and return */ +void err_msg_n(int err, char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + err_doit(err, fmt, ap); + va_end(ap); + return; +} + +/* print an error message and quit */ +void err_quit(char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + err_doit(0, fmt, ap); + va_end(ap); + exit(1); +} + +void err_doit(int err, const char *fmt, va_list ap) +{ + if (err) + fprintf(stderr, "%s\n", strerror(err)); + vfprintf(stderr, fmt, ap); + return; +} diff --git a/src/lib/error.h b/src/lib/error.h new file mode 100644 index 0000000..90d6e94 --- /dev/null +++ b/src/lib/error.h @@ -0,0 +1,14 @@ +#ifndef __ERROR_H +#define __ERROR_H + +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> + +void err_exit(int err, char *fmt, ...); +void err_msg(char *fmt, ...); +void err_msg_n(int err, char *fmt, ...); +void err_quit(char *fmt, ...); +void err_doit(int err, const char *fmt, va_list ap); + +#endif /* __ERROR_H */ -- 1.6.5.2 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/5] rt-tests: Add a new test pip - priority inheritance with processes 2009-12-23 16:02 ` [PATCH 1/5] rt-tests: Add error routines to the library John Kacur @ 2009-12-23 16:02 ` John Kacur 2009-12-23 16:02 ` [PATCH 3/5] rt-tests: Move header files from src/lib to src/include John Kacur 2009-12-23 22:52 ` [PATCH 2/5] rt-tests: Add a new test pip - priority inheritance with processes Carsten Emde 0 siblings, 2 replies; 8+ messages in thread From: John Kacur @ 2009-12-23 16:02 UTC (permalink / raw) To: Clark Williams, Carsten Emde; +Cc: John Kacur, rt-users, Thomas Gleixner This test is similar to pi_stress in that it purpursely triggers a priority- inversion. However, instead of using pthreads it uses processes. Since pthread_mutex_t are the only objects backed by priority inheritance this is accomplished by having the processes use a pthread_mutex_t in shared memory. See the header of pip.c for more information as well as the code of course. In addition this patch starts a src/include directory as a common place to put header files. Signed-off-by: John Kacur <jkacur@redhat.com> --- .gitignore | 2 +- Makefile | 7 +- src/include/error.h | 15 +++ src/include/pip.h | 40 ++++++ src/lib/error.h | 14 -- src/pi_tests/pip.c | 344 +++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 405 insertions(+), 17 deletions(-) create mode 100644 src/include/error.h create mode 100644 src/include/pip.h delete mode 100644 src/lib/error.h create mode 100644 src/pi_tests/pip.c diff --git a/.gitignore b/.gitignore index d03a635..a914a3f 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,4 @@ ptsematest sendme sigwaittest svsematest - +pip diff --git a/Makefile b/Makefile index 137cd0f..df5a2f4 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ VERSION_STRING = 0.59 TARGETS = cyclictest signaltest pi_stress \ hwlatdetect rt-migrate-test ptsematest sigwaittest svsematest \ - sendme + sendme pip LIBS = -lpthread -lrt EXTRA_LIBS ?= -ldl # for get_cpu DESTDIR ?= @@ -11,7 +11,7 @@ bindir ?= $(prefix)/bin mandir ?= $(prefix)/share/man srcdir ?= $(prefix)/src -CFLAGS = -D_GNU_SOURCE -Wall -Wno-nonnull -Isrc/lib +CFLAGS = -D_GNU_SOURCE -Wall -Wno-nonnull -Isrc/lib -Isrc/include ifndef DEBUG CFLAGS += -O2 @@ -63,6 +63,9 @@ svsematest: svsematest.o rt-utils.o rt-get_cpu.o sendme: sendme.o rt-utils.o rt-get_cpu.o $(CC) $(CFLAGS) -o $@ $^ $(LIBS) $(EXTRA_LIBS) +pip: pip.o error.o + $(CC) $(CFLAGS) -o $@ $^ $(LIBS) + CLEANUP = $(TARGETS) *.o .depend *.*~ *.orig *.rej rt-tests.spec CLEANUP += $(if $(wildcard .git), ChangeLog) diff --git a/src/include/error.h b/src/include/error.h new file mode 100644 index 0000000..512b3a6 --- /dev/null +++ b/src/include/error.h @@ -0,0 +1,15 @@ +#ifndef __ERROR_H +#define __ERROR_H + +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#include <string.h> + +void err_exit(int err, char *fmt, ...); +void err_msg(char *fmt, ...); +void err_msg_n(int err, char *fmt, ...); +void err_quit(char *fmt, ...); +void err_doit(int err, const char *fmt, va_list ap); + +#endif /* __ERROR_H */ diff --git a/src/include/pip.h b/src/include/pip.h new file mode 100644 index 0000000..01a31c3 --- /dev/null +++ b/src/include/pip.h @@ -0,0 +1,40 @@ +#ifndef __PIP_H +#define __PIP_H + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <errno.h> +#include <sys/mman.h> +#include <string.h> +#include <stdarg.h> +#include <pthread.h> +#include <sys/types.h> +#include <sys/wait.h> +#include <signal.h> +#include <sched.h> +#include "error.h" + +void low(pid_t pid); /* low priority process */ +void medium(void); /* medium priority process */ +void high(pid_t pid); /* high priority process */ +void init_state(void); + +void *mmap_page(void); +long process_shared_mutex_available(void); +void Pthread_mutexattr_init(pthread_mutexattr_t *attr); +void Pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared); +void Pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr, int protocol); +void Pthread_mutex_init(pthread_mutex_t *mutex, pthread_mutexattr_t *attr); +void Pthread_mutex_lock(pthread_mutex_t *mutex); +void Pthread_mutex_unlock(pthread_mutex_t *mutex); + +void init_shared_pthread_mutex(pthread_mutex_t *mutex, int protocol, int policy); +int set_rt_prio(pid_t pid, int prio, int policy); +int get_rt_prio(pid_t pid); + +#define PROTRW PROT_READ|PROT_WRITE +#define MMAP_FLAGS MAP_SHARED|MAP_ANONYMOUS + +#endif /* __PIP_H */ + diff --git a/src/lib/error.h b/src/lib/error.h deleted file mode 100644 index 90d6e94..0000000 --- a/src/lib/error.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef __ERROR_H -#define __ERROR_H - -#include <stdio.h> -#include <stdlib.h> -#include <stdarg.h> - -void err_exit(int err, char *fmt, ...); -void err_msg(char *fmt, ...); -void err_msg_n(int err, char *fmt, ...); -void err_quit(char *fmt, ...); -void err_doit(int err, const char *fmt, va_list ap); - -#endif /* __ERROR_H */ diff --git a/src/pi_tests/pip.c b/src/pi_tests/pip.c new file mode 100644 index 0000000..ce3f5d9 --- /dev/null +++ b/src/pi_tests/pip.c @@ -0,0 +1,344 @@ +/* + Pip - Priority Inheritance with processes + + Copyright (C) 2009, John Kacur <jkacur@redhat.com> + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/* + * This program demonstrates the technique of using priority inheritance (PI) + * mutexes with processes instead of threads. + * The way to do this is to obtain some shared memory - in this case with + * mmap that backs a pthread_mutex_t since this will support PI. + * Pay particular attention to how this is intialized to support processes. + * Function init_shared_pthread_mutex() does this by setting the + * pthread_mutexattr to PTHREAD_PROCESS_SHARED and the mutex protocol to + * PTHREAD_PRIO_INHERIT. + * In this program we purposely try to invoke a classic priority inversion. + * A low priority process grabs the mutex and does some work. + * A high priority process comes a long and is blocked since the mutex is taken. + * A medium priority process that doesn't require the mutex then takes the + * processor. Because the processes are restricted to one cpu, the low priority + * processes never makes any progress because the medium priority process + * runs in an infinite loop. This is a priority inversion because the + * medium priority process is running at the expensive of the high priority + * process. However, since we have used PRIO_INHERIT and are running on a + * machine that supports preemption, the high priority process will lend it's + * priority to the low priority process which will preempt the medium priority + * process. The low priority process will then release the mutex which the + * high priority process can obtain. When the high priority process gets to run + * it kills the medium priority process. + * The state structure keeps track of the progress. Although this program + * is set up to likely trigger an inversion, there is no guarantee that + * scheduling will make that happen. After the program completes it reports + * whether a priority inversion occurred or not. In either case this program + * demonstrates how to use priority inheritance mutexes with processes. + * In fact, you would be better off to avoid scenarios in which a priority + * inversion occurs if possible - this program tries to trigger them just + * to show that it works. If you are having difficulty triggering an inversion, + * merely increase the time that the low priority process sleeps while + * holding the lock. (usleep); + * Also note that you have to run as a user with permission to change + * scheduling priorities. + */ + +#include "pip.h" + +pthread_mutex_t *resource; + +/* This records the state to determine whether a priority inversion occured */ +struct State { + int low_owns_resource; + int high_started; + int high_owns_resource; + int medium_started; + int inversion; + pthread_mutex_t *mutex; +}; + +struct State *statep; + +const int policy = SCHED_FIFO; +const int prio_min; /* Initialized for the minimum priority of policy */ + +int main(void) +{ + void *mptr; /* memory pointer */ + pid_t pid1, pid2; + cpu_set_t set, *setp = &set; + int res; + int *minimum_priority = (int*)&prio_min; + + *minimum_priority = sched_get_priority_min(policy); + + mptr = mmap_page(); /* Get a page of shared memory */ + resource = (pthread_mutex_t*)mptr; /* point our lock to it */ + mptr += sizeof(pthread_mutex_t); /* advance the memory pointer */ + + /* Initialize our mutex via the resource pointer */ + init_shared_pthread_mutex(resource, PTHREAD_PRIO_INHERIT, policy); + + statep = (struct State*)mptr; + mptr += sizeof(struct State); + + init_state(); /* Initialize the state structure */ + + statep->mutex = (pthread_mutex_t*)mptr; /* point the next lock to it */ + mptr += sizeof(pthread_mutex_t); /* advance the memory pointer */ + + /* Initialize our State mutex */ + init_shared_pthread_mutex(statep->mutex, PTHREAD_PRIO_NONE, policy); + + set_rt_prio(0, prio_min, policy); + + /* We restrict this program to the first cpu, inorder to increase + * the likelihood of a priority inversion */ + CPU_ZERO(setp); + CPU_SET(0, setp); + res = sched_setaffinity(0, sizeof(set), setp); + if (res == -1) { + int err = errno; + err_msg("sched_setaffinity: "); + err_exit(err, NULL); + } + + pid1 = fork(); + if (pid1 == -1) { + perror("fork"); + exit(1); + } else if (pid1 != 0) { /* parent code */ + low(pid1); + } else { /* child code */ + pid2 = fork(); /* parent code */ + if (pid2 == -1) { + perror("fork: "); + exit(-1); + } else if (pid2 != 0) { /* parent code */ + high(pid2); + } else { /* child code */ + medium(); + } + } + + exit(0); +} + +/* Initialize the structure that tracks when a priority inversion occurs */ +void init_state(void) +{ + /* Init the State structure */ + statep->low_owns_resource = 0; + statep->high_started = 0; + statep->high_owns_resource = 0; + statep->medium_started = 0; + /* Assume an inversion will occur until proven false */ + statep->inversion = 1; +} + +/* @pid = high priority process pid */ +void low(pid_t pid) +{ + int status; + Pthread_mutex_lock(resource); + Pthread_mutex_lock(statep->mutex); + statep->low_owns_resource = 1; + if (statep->high_owns_resource || + statep->medium_started) { + statep->inversion = 0; + } + Pthread_mutex_unlock(statep->mutex); + usleep(500); + Pthread_mutex_unlock(resource); + waitpid(pid, &status, 0); +} + +void medium(void) +{ + set_rt_prio(0, prio_min+1, policy); + Pthread_mutex_lock(statep->mutex); + statep->medium_started = 1; + if (!statep->high_started) + statep->inversion = 0; + Pthread_mutex_unlock(statep->mutex); + + for(;;); /* infinite loop */ +} + +/* @pid = medium priority process pid */ +void high(pid_t pid) +{ + int status; + set_rt_prio(0, prio_min+2, policy); + + /* Must come after raising the priority */ + Pthread_mutex_lock(statep->mutex); + statep->high_started = 1; + Pthread_mutex_unlock(statep->mutex); + + Pthread_mutex_lock(resource); + Pthread_mutex_lock(statep->mutex); + statep->high_owns_resource = 1; + if (!statep->low_owns_resource || !statep->medium_started) { + statep->inversion = 0; + } + Pthread_mutex_unlock(statep->mutex); + Pthread_mutex_unlock(resource); + kill(pid, SIGKILL); /* kill the medium thread */ + waitpid(pid, &status, 0); + + Pthread_mutex_lock(statep->mutex); + + if (statep->inversion) + printf("Successfully used priority inheritance to handle an inversion\n"); + else { + printf("No inversion incurred\n"); + } + Pthread_mutex_unlock(statep->mutex); +} + +/* mmap a page of anonymous shared memory */ +void *mmap_page(void) +{ + void *mptr; + long pgsize = sysconf(_SC_PAGE_SIZE); + + mptr = mmap(NULL, pgsize, PROTRW, MMAP_FLAGS, 0, 0); + if (mptr == MAP_FAILED) { + perror("In function mmap_page - mmap"); + exit(-1); + } + + return mptr; +} + +long process_shared_mutex_available(void) +{ + long res = -1; /* undefined */ +#ifdef _POSIX_THREAD_PROCESS_SHARED + res = sysconf(_SC_THREAD_PROCESS_SHARED); + if (res == -1) { + int err = errno; /* save the error number */ + err_msg("%s: sysconf(_SC_THREAD_PROCESS_SHARED): "); + err_exit(err, NULL); + } +#else +#error _POSIX_THREAD_PROCESS_SHARED is not defined +#endif + return res; +} + +void Pthread_mutexattr_init(pthread_mutexattr_t *attr) +{ + int err; + err = pthread_mutexattr_init(attr); + if (err) { + err_msg("%s: pthread_mutexattr_init(): ", __func__); + err_exit(err, NULL); + } +} + +void Pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared) +{ + int err; + err = pthread_mutexattr_setpshared(attr, pshared); + if (err) { + err_msg("%s: pthread_mutexattr_setpshared(): ", __func__); + err_exit(err, NULL); + } +} + +void Pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr, int protocol) +{ + int err; + err = pthread_mutexattr_setprotocol(attr, protocol); + if (err) { + err_msg("%s: pthread_mutexattr_setprotocol(): ", __func__); + err_exit(err, NULL); + } +} + +void Pthread_mutex_init(pthread_mutex_t *mutex, pthread_mutexattr_t *attr) +{ + int err; + err = pthread_mutex_init(mutex, attr); + if (err) { + err_msg("%s: pthread_mutex_init(): ", __func__); + err_exit(err, NULL); + } +} + +void Pthread_mutex_lock(pthread_mutex_t *mutex) +{ + int err; + err = pthread_mutex_lock(mutex); + if (err) { + err_msg("%s: pthread_mutex_lock(): ", __func__); + err_exit(err, NULL); + } +} + +void Pthread_mutex_unlock(pthread_mutex_t *mutex) +{ + int err; + err = pthread_mutex_unlock(mutex); + if (err) { + err_msg("%s: pthread_mutex_unlock(): ", __func__); + err_exit(err, NULL); + } +} + +void init_shared_pthread_mutex(pthread_mutex_t *mutex, int protocol, int policy) +{ + pthread_mutexattr_t attr; + + process_shared_mutex_available(); + + Pthread_mutexattr_init(&attr); + Pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED); + Pthread_mutexattr_setprotocol(&attr, protocol); + + Pthread_mutex_init(mutex, &attr); +} + +/* Set the priority and policy of a process */ +int set_rt_prio(pid_t pid, int prio, int policy) +{ + int err; + struct sched_param param; + struct sched_param *pparam = ¶m; + pparam->sched_priority = prio; + err = sched_setscheduler(pid, policy, pparam); + if (err) { + err = errno; /* save the errno */ + err_msg_n(err, "%s: sched_setscheduler(): ", __func__); + err_msg("%s: prio = %d\n", __func__, prio); + err_msg("%s: pparam->sched_priority = %d\n", __func__, pparam->sched_priority); + err_msg("%s: policy = %d\n", __func__, policy); + } + return err; /* 0 on success */ +} + +int get_rt_prio(pid_t pid) +{ + int err; + struct sched_param param; + err = sched_getparam(pid, ¶m); + if (err) { + err = errno; /* save the errno */ + err_msg_n(err, "%s: get_rt_prio(): ", __func__); + return -1; + } + return param.sched_priority; +} -- 1.6.5.2 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/5] rt-tests: Move header files from src/lib to src/include 2009-12-23 16:02 ` [PATCH 2/5] rt-tests: Add a new test pip - priority inheritance with processes John Kacur @ 2009-12-23 16:02 ` John Kacur 2009-12-23 16:02 ` [PATCH 4/5] rt-tests: pip - Use check_privs() from the rt-utils library John Kacur 2009-12-23 22:52 ` [PATCH 2/5] rt-tests: Add a new test pip - priority inheritance with processes Carsten Emde 1 sibling, 1 reply; 8+ messages in thread From: John Kacur @ 2009-12-23 16:02 UTC (permalink / raw) To: Clark Williams, Carsten Emde; +Cc: John Kacur, rt-users, Thomas Gleixner Move header files from src/lib to src/include and adjust the Makefile to reflect this change. Signed-off-by: John Kacur <jkacur@redhat.com> --- Makefile | 2 +- src/include/rt-get_cpu.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/include/rt-utils.h | 11 +++++++++++ src/lib/rt-get_cpu.h | 46 ---------------------------------------------- src/lib/rt-utils.h | 11 ----------- 5 files changed, 58 insertions(+), 58 deletions(-) create mode 100644 src/include/rt-get_cpu.h create mode 100644 src/include/rt-utils.h delete mode 100644 src/lib/rt-get_cpu.h delete mode 100644 src/lib/rt-utils.h diff --git a/Makefile b/Makefile index df5a2f4..b30a139 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ bindir ?= $(prefix)/bin mandir ?= $(prefix)/share/man srcdir ?= $(prefix)/src -CFLAGS = -D_GNU_SOURCE -Wall -Wno-nonnull -Isrc/lib -Isrc/include +CFLAGS = -D_GNU_SOURCE -Wall -Wno-nonnull -Isrc/include ifndef DEBUG CFLAGS += -O2 diff --git a/src/include/rt-get_cpu.h b/src/include/rt-get_cpu.h new file mode 100644 index 0000000..15d05fc --- /dev/null +++ b/src/include/rt-get_cpu.h @@ -0,0 +1,46 @@ +#ifndef __RT_GET_CPU_H +#define __RT_GET_CPU_H +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> +#include <unistd.h> +#include <sys/syscall.h> /* For SYS_xxx definitions */ +#include <sched.h> +#include <dlfcn.h> +#ifdef __NR_getcpu +static inline int get_cpu_setup(void) { return 0; } +static inline int get_cpu(void) +{ + int c,s; + /* Show the source of get_cpu */ +#ifdef DEBUG + fprintf(stderr, "__NR_getcpu\n"); +#endif + s = syscall(__NR_getcpu, &c, NULL, NULL); + return (s == -1) ? s : c; +} +#elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) \ + && __GLIBC__>=2 && __GLIBC_MINOR__>=6 +#include <utmpx.h> +static inline int get_cpu_setup(void) { return 0; } +static inline int get_cpu(void) { return sched_getcpu(); } +#else +extern int get_cpu_setup(void); +extern int (*get_cpu)(void); +extern int (*get_cpu_vdsop)(unsigned int *, unsigned int *, void *); + +static inline int getcpu_vdso(void) +{ + unsigned int c,s; + /* Show the source of get_cpu */ +#ifdef DEBUG + fprintf(stderr, "getcpu_vdso\n"); +#endif + s = get_cpu_vdsop(&c, NULL, NULL); + return (s == -1) ? s : c; +} + +#endif + +#endif /* __RT_GET_CPU_H */ + diff --git a/src/include/rt-utils.h b/src/include/rt-utils.h new file mode 100644 index 0000000..cc23c33 --- /dev/null +++ b/src/include/rt-utils.h @@ -0,0 +1,11 @@ +#ifndef __RT_UTILS_H +#define __RT_UTILS_H + +#define _STR(x) #x +#define STR(x) _STR(x) +#define MAX_PATH 256 + +int check_privs(void); +char *get_debugfileprefix(void); + +#endif /* __RT_UTILS.H */ diff --git a/src/lib/rt-get_cpu.h b/src/lib/rt-get_cpu.h deleted file mode 100644 index 15d05fc..0000000 --- a/src/lib/rt-get_cpu.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef __RT_GET_CPU_H -#define __RT_GET_CPU_H -#include <stdio.h> -#include <stdlib.h> -#include <errno.h> -#include <unistd.h> -#include <sys/syscall.h> /* For SYS_xxx definitions */ -#include <sched.h> -#include <dlfcn.h> -#ifdef __NR_getcpu -static inline int get_cpu_setup(void) { return 0; } -static inline int get_cpu(void) -{ - int c,s; - /* Show the source of get_cpu */ -#ifdef DEBUG - fprintf(stderr, "__NR_getcpu\n"); -#endif - s = syscall(__NR_getcpu, &c, NULL, NULL); - return (s == -1) ? s : c; -} -#elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) \ - && __GLIBC__>=2 && __GLIBC_MINOR__>=6 -#include <utmpx.h> -static inline int get_cpu_setup(void) { return 0; } -static inline int get_cpu(void) { return sched_getcpu(); } -#else -extern int get_cpu_setup(void); -extern int (*get_cpu)(void); -extern int (*get_cpu_vdsop)(unsigned int *, unsigned int *, void *); - -static inline int getcpu_vdso(void) -{ - unsigned int c,s; - /* Show the source of get_cpu */ -#ifdef DEBUG - fprintf(stderr, "getcpu_vdso\n"); -#endif - s = get_cpu_vdsop(&c, NULL, NULL); - return (s == -1) ? s : c; -} - -#endif - -#endif /* __RT_GET_CPU_H */ - diff --git a/src/lib/rt-utils.h b/src/lib/rt-utils.h deleted file mode 100644 index cc23c33..0000000 --- a/src/lib/rt-utils.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef __RT_UTILS_H -#define __RT_UTILS_H - -#define _STR(x) #x -#define STR(x) _STR(x) -#define MAX_PATH 256 - -int check_privs(void); -char *get_debugfileprefix(void); ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 4/5] rt-tests: pip - Use check_privs() from the rt-utils library. 2009-12-23 16:02 ` [PATCH 3/5] rt-tests: Move header files from src/lib to src/include John Kacur @ 2009-12-23 16:02 ` John Kacur 2009-12-23 16:03 ` [PATCH 5/5] rt-tests: Add a "make tags" option John Kacur 0 siblings, 1 reply; 8+ messages in thread From: John Kacur @ 2009-12-23 16:02 UTC (permalink / raw) To: Clark Williams, Carsten Emde; +Cc: John Kacur, rt-users, Thomas Gleixner Use check_privs() from the rt-utils library to make sure that the user is running with real-time privileges for the pip test program. Signed-off-by: John Kacur <jkacur@redhat.com> --- Makefile | 2 +- src/include/pip.h | 1 + src/pi_tests/pip.c | 3 +++ 3 files changed, 5 insertions(+), 1 deletions(-) diff --git a/Makefile b/Makefile index b30a139..3339556 100644 --- a/Makefile +++ b/Makefile @@ -63,7 +63,7 @@ svsematest: svsematest.o rt-utils.o rt-get_cpu.o sendme: sendme.o rt-utils.o rt-get_cpu.o $(CC) $(CFLAGS) -o $@ $^ $(LIBS) $(EXTRA_LIBS) -pip: pip.o error.o +pip: pip.o error.o rt-utils.o $(CC) $(CFLAGS) -o $@ $^ $(LIBS) CLEANUP = $(TARGETS) *.o .depend *.*~ *.orig *.rej rt-tests.spec diff --git a/src/include/pip.h b/src/include/pip.h index 01a31c3..b2068be 100644 --- a/src/include/pip.h +++ b/src/include/pip.h @@ -13,6 +13,7 @@ #include <sys/wait.h> #include <signal.h> #include <sched.h> +#include <rt-utils.h> #include "error.h" void low(pid_t pid); /* low priority process */ diff --git a/src/pi_tests/pip.c b/src/pi_tests/pip.c index ce3f5d9..085908b 100644 --- a/src/pi_tests/pip.c +++ b/src/pi_tests/pip.c @@ -83,6 +83,9 @@ int main(void) *minimum_priority = sched_get_priority_min(policy); + if (check_privs()) + exit(-1); + mptr = mmap_page(); /* Get a page of shared memory */ resource = (pthread_mutex_t*)mptr; /* point our lock to it */ mptr += sizeof(pthread_mutex_t); /* advance the memory pointer */ -- 1.6.5.2 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 5/5] rt-tests: Add a "make tags" option. 2009-12-23 16:02 ` [PATCH 4/5] rt-tests: pip - Use check_privs() from the rt-utils library John Kacur @ 2009-12-23 16:03 ` John Kacur 0 siblings, 0 replies; 8+ messages in thread From: John Kacur @ 2009-12-23 16:03 UTC (permalink / raw) To: Clark Williams, Carsten Emde; +Cc: John Kacur, rt-users, Thomas Gleixner Add a "make tags" option to the Makefile Signed-off-by: John Kacur <jkacur@redhat.com> --- Makefile | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/Makefile b/Makefile index 3339556..c33a053 100644 --- a/Makefile +++ b/Makefile @@ -73,6 +73,7 @@ CLEANUP += $(if $(wildcard .git), ChangeLog) clean: for F in $(CLEANUP); do find -type f -name $$F | xargs rm -f; done rm -f hwlatdetect + rm -f tags .PHONY: distclean distclean: clean @@ -144,3 +145,7 @@ help: @echo " clean : remove object files" @echo " distclean : remove all generated files" @echo " help : print this message" + +.PHONY: tags +tags: + ctags -R --extra=+f --c-kinds=+p * -- 1.6.5.2 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 2/5] rt-tests: Add a new test pip - priority inheritance with processes 2009-12-23 16:02 ` [PATCH 2/5] rt-tests: Add a new test pip - priority inheritance with processes John Kacur 2009-12-23 16:02 ` [PATCH 3/5] rt-tests: Move header files from src/lib to src/include John Kacur @ 2009-12-23 22:52 ` Carsten Emde 2009-12-23 23:25 ` John Kacur 1 sibling, 1 reply; 8+ messages in thread From: Carsten Emde @ 2009-12-23 22:52 UTC (permalink / raw) To: John Kacur; +Cc: Clark Williams, rt-users, Thomas Gleixner John, When creating an RPM package with the newly provided test pip, the message error: Installed (but unpackaged) file(s) found: /usr/bin/pip appeared, and rpmbuild refused to finish building the package. Carsten. -=--------------------------------------------------------------------=- Prevent rpmbuild from finding installed but unpackaged files. Signed-off-by: Carsten Emde <C.Emde@osadl.org> diff --git a/rt-tests.spec-in b/rt-tests.spec-in index 5ca08ee..a55a9ba 100644 --- a/rt-tests.spec-in +++ b/rt-tests.spec-in @@ -35,6 +35,7 @@ rm -rf $RPM_BUILD_ROOT /usr/bin/signaltest /usr/bin/hwlatdetect /usr/bin/rt-migrate-test +/usr/bin/pip /usr/bin/ptsematest /usr/bin/sendme /usr/bin/sigwaittest ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 2/5] rt-tests: Add a new test pip - priority inheritance with processes 2009-12-23 22:52 ` [PATCH 2/5] rt-tests: Add a new test pip - priority inheritance with processes Carsten Emde @ 2009-12-23 23:25 ` John Kacur 0 siblings, 0 replies; 8+ messages in thread From: John Kacur @ 2009-12-23 23:25 UTC (permalink / raw) To: Carsten Emde; +Cc: Clark Williams, rt-users, Thomas Gleixner On Wed, 23 Dec 2009, Carsten Emde wrote: > John, > > When creating an RPM package with the newly provided test pip, the message > error: Installed (but unpackaged) file(s) found: > /usr/bin/pip > appeared, and rpmbuild refused to finish building the package. > > Carsten. > > -=--------------------------------------------------------------------=- > > Prevent rpmbuild from finding installed but unpackaged files. > > Signed-off-by: Carsten Emde <C.Emde@osadl.org> > > diff --git a/rt-tests.spec-in b/rt-tests.spec-in > index 5ca08ee..a55a9ba 100644 > --- a/rt-tests.spec-in > +++ b/rt-tests.spec-in > @@ -35,6 +35,7 @@ rm -rf $RPM_BUILD_ROOT > /usr/bin/signaltest > /usr/bin/hwlatdetect > /usr/bin/rt-migrate-test > +/usr/bin/pip > /usr/bin/ptsematest > /usr/bin/sendme > /usr/bin/sigwaittest > Thanks Carsten. Your patch applied cleanly without problems. I pushed it to my tree. git://git.kernel.org/pub/scm/linux/kernel/git/jkacur/rt-tests.git branch: rt-tests-dev-new (2fc5d42) Clark, you can pull from above. Thanks ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2009-12-23 23:26 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2009-12-23 16:02 [PATCH 0/5] *** Add new priority inversion test, plus lib changes *** John Kacur 2009-12-23 16:02 ` [PATCH 1/5] rt-tests: Add error routines to the library John Kacur 2009-12-23 16:02 ` [PATCH 2/5] rt-tests: Add a new test pip - priority inheritance with processes John Kacur 2009-12-23 16:02 ` [PATCH 3/5] rt-tests: Move header files from src/lib to src/include John Kacur 2009-12-23 16:02 ` [PATCH 4/5] rt-tests: pip - Use check_privs() from the rt-utils library John Kacur 2009-12-23 16:03 ` [PATCH 5/5] rt-tests: Add a "make tags" option John Kacur 2009-12-23 22:52 ` [PATCH 2/5] rt-tests: Add a new test pip - priority inheritance with processes Carsten Emde 2009-12-23 23:25 ` John Kacur
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).