On 26 November 2013 00:40, Joel Sherrill <joel.sherr...@oarcorp.com> wrote:
> On 11/25/2013 10:58 AM, Chirayu Desai wrote: > > > > Sorry, I sent the last message to only Joel. > > I MIGHT have eventually gotten to it. But am swamped. > > > ---------- Forwarded message ---------- > > From: *Chirayu Desai* <chirayudes...@gmail.com > > <mailto:chirayudes...@gmail.com>> > > Date: 25 November 2013 15:30 > > Subject: Re: Help with debugging a POSIX timing test. > > To: Joel Sherrill <joel.sherr...@oarcorp.com > > <mailto:joel.sherr...@oarcorp.com>> > > > > > > > > > > > > On 25 November 2013 00:35, Joel Sherrill <joel.sherr...@oarcorp.com > > <mailto:joel.sherr...@oarcorp.com>> wrote: > > > > Now that I can see and run the code, a few things > > jump out. > > > > + POSIX priorities -- lower numerically ==> more important > > + You did &Thread_Id to calls after created. The & isn't > > supposed to be there. > > > > + &policy should be the second argument to > > pthread_getschedparam. > > > > This explains the ESRCH I was getting. > > Yep. And one of the compiler warnings as well. :) > > > + Pay attention to compiler warnings. :) > > > > Sorry for not doing so. > > No problem. This is a good example of how properly addressing > the warning would have fixed the issue with no time in the > debugger. Good programming practices try to keep you out of > a debugger. :) > > > + Benchmark time is initialized IMMEDIATELY BEFORE the > > single operation under test. We try to avoid including > > anything. > > > > Got it. > > > > > > I have attached a new version of init.c with comments > > hacked in and changes. > > > > Thanks. > > > > > > The big thing I tried to put in a comment block is that > > the way this test is structured, it includes the hidden > > start up time for the first time test_thread(0 runs. > > I tried to write up notes on how to modify the test > > to avoid that. > > > > I was unable to understand all of it. > > From what I understood, POSIX_Init is called first, which > > cals benchmark_pthread_setschedparam. > > That creates a new thread, gets the priority and policy, and then > > setschedparam is called > > with the new (lowered) priority, which is what we want to test. > > pthread_create() creates and starts the thread. If it is > more important than POSIX_Init(), it will immediately be > switched to and run. But it isn't so it won't run until > POSIX_Init() lowers its priority. > That makes it much more clear. > > > > For convenience, I would add a helper routine like > > this: > > > > void set_thread_priority( id, new_priority ) > > > > and call it. It will greatly simplify the code. > > > > Noted, I will do that after I get a better understanding of the code. > > Since you will be changing priority multiple times to switch > back and forth, this will really help tighten the code. > Done [0] :) > > > > I hope I didn't fall into the inverse > > priority range trap in those instructions.... > > > > WARNING: POSIX priorities run INVERSE from the internal > > priorities but in gdb if you print: > > > > p _Per_CPU_Information.per_cpu.executing->current_priority > > > > You will see the internal priority (NOT POSIX priority) > > of the currently running thread. 1 is most important > > and 255 is the IDLE task. > > > > I'm confused. > > Per > http://www.rtems.org/onlinedocs/doxygen/cpukit/html/group__POSIX__PRIORITY.html#gada0c9a015d42fd545af7454f1ca0d098 > , > > "RTEMS Core has priorities run in the opposite sense of the POSIX API." > > So, for this task, lowering the POSIX priority is what we want, it is > > the output I'm getting which confuses me > > > > Original priority: 2 > > Lowered priority: 4 > > I am going to do this as a mix of internal and > POSIX priorities > > Internal 255 is the lowest priority and illegal in POSIX. > Internal 253 = POSIX_Init() at start (POSIX 2) > see cpukit/posix/src/pthread.c for the default attributes > > Where you say lowered, it is actually becoming more important > and moving to a numeric value with numbers above and below. > At 2, there is little room below it. It is the next to lowest > POSIX priority value. > > test_thread() is created at priority 2 also because the > attributes are NULL. > > What you print as "Lowered priority" is actually the priority > of test_thread() if I am reading things correctly. > > Hint: Make your set priority helper take (const char *, id, priority) > and you can print the thread name in debug messages. :) > > When I break at test_thread(), the priority is POSIX=4, Internal=251 > > I'm getting the hang of this now. > > > So the numbers you pick are important to switch back and > > forth between the tasks. > > > > I think the test is pretty close in spite of all that I > > wrong. I stepped through the code attached and it is > > doing the right thing EXCEPT including the thread hidden > > start time. :) > > > > Benchmark programs are hard to get right but fun to write. > > > > Indeed > > :) > > Hope this helps. > > Stepping in gdb and printing the priority of the current thread > helps. It will be the internal priority though. > > b POSIX_Init > b test_thread > > and use > > p _Per_CPU_Information.per_cpu.executing->current_priority > > Using breakpoints did help, thanks. I have attached a new patch, and cross-posted it to melange as well. > > > > > --joel > > > > On 11/24/2013 11:50 AM, Joel Sherrill wrote: > > > Sorry to be lazy/stupid but how to I download just > > > the diff to see what's going on? I am not that > > > github literate. > > > > > > --joel > > > > > > On 11/24/2013 11:28 AM, Chirayu Desai wrote: > > >> Hello everyone. > > >> > > >> I am Chirayu Desai, a high school student, currently > participating in > > >> Google Code-In 2013 > > >> > > >> I have currently working on the task [0], but I'm having some > trouble > > >> trying to get my code[1] to work. > > >> > > >> The task is to create a POSIX timing test psxtmthread05. > > >> The test case is: pthread_setschedparam() - lower own priority. > > >> I managed to write up something [2], but it doesn't work. > > >> The GDB output is: > > >> > > >> (gdb) r > > >> Starting program: > > >> > > > /home/cdesai/rtems/b-sis/sparc-rtems4.11/c/sis/testsuites/psxtmtests/psxtmthread05/psxtmthread05.exe > > >> > > >> > > >> *** POSIX TIME TEST PSXTMTHREAD05 *** > > >> getschedparam: 3 > > >> Original priority: 5 > > >> Lowered priority: 4 > > >> setschedparam: 3 > > >> pthread_setschedparam - lower own priority 2226 > > >> *** END OF POSIX TIME TEST PSXTMTHREAD05 *** > > >> [Inferior 1 (process 42000) exited normally] > > >> > > >> [0]: > > >> > > > http://www.google-melange.com/gci/task/view/google/gci2013/6383096106582016 > > >> [1]: https://github.com/chirayudesai/rtems/tree/psxtmthread05 > > >> [2]: > > > https://github.com/chirayudesai/rtems/commit/890cebf084ca2a3815e3049a766276ddcdb0188a > > >> > > >> P.S. This is my first post to this list, so excuse me for any > > mistakes. > > >> > > >> Regards, > > >> Chirayu Desai > > > > > > > > > > > > > > > > > -- > > Joel Sherrill, Ph.D. Director of Research & Development > > joel.sherr...@oarcorp.com On-Line Applications Research > > Ask me about RTEMS: a free RTOS Huntsville AL 35805 > > Support Available (256) 722-9985 > > > > > > > > > > -- > Joel Sherrill, Ph.D. Director of Research & Development > joel.sherr...@oarcorp.com On-Line Applications Research > Ask me about RTEMS: a free RTOS Huntsville AL 35805 > Support Available (256) 722-9985 >
From 83e5768363992764711ffd2993433d52621ce6e7 Mon Sep 17 00:00:00 2001 From: Chirayu Desai <cde...@cyanogenmod.org> Date: Sun, 24 Nov 2013 12:34:13 +0530 Subject: [PATCH] Add a test for pthread_setschedparam - lower own priority psxtmthread05 GCI-2013 task: http://www.google-melange.com/gci/task/view/google/gci2013/6383096106582016 --- testsuites/psxtmtests/Makefile.am | 1 + testsuites/psxtmtests/configure.ac | 1 + testsuites/psxtmtests/psxtmthread05/Makefile.am | 27 ++++++ testsuites/psxtmtests/psxtmthread05/init.c | 105 +++++++++++++++++++++ .../psxtmtests/psxtmthread05/psxtmthread05.doc | 11 +++ 5 files changed, 145 insertions(+) create mode 100644 testsuites/psxtmtests/psxtmthread05/Makefile.am create mode 100644 testsuites/psxtmtests/psxtmthread05/init.c create mode 100644 testsuites/psxtmtests/psxtmthread05/psxtmthread05.doc diff --git a/testsuites/psxtmtests/Makefile.am b/testsuites/psxtmtests/Makefile.am index be21fa2..812c3ad 100644 --- a/testsuites/psxtmtests/Makefile.am +++ b/testsuites/psxtmtests/Makefile.am @@ -42,6 +42,7 @@ SUBDIRS += psxtmsleep02 SUBDIRS += psxtmthread01 SUBDIRS += psxtmthread02 SUBDIRS += psxtmthread03 +SUBDIRS += psxtmthread05 endif DIST_SUBDIRS = $(SUBDIRS) diff --git a/testsuites/psxtmtests/configure.ac b/testsuites/psxtmtests/configure.ac index 9eedb89..0e70274 100644 --- a/testsuites/psxtmtests/configure.ac +++ b/testsuites/psxtmtests/configure.ac @@ -116,5 +116,6 @@ psxtmsleep02/Makefile psxtmthread01/Makefile psxtmthread02/Makefile psxtmthread03/Makefile +psxtmthread05/Makefile ]) AC_OUTPUT diff --git a/testsuites/psxtmtests/psxtmthread05/Makefile.am b/testsuites/psxtmtests/psxtmthread05/Makefile.am new file mode 100644 index 0000000..8c3cf66 --- /dev/null +++ b/testsuites/psxtmtests/psxtmthread05/Makefile.am @@ -0,0 +1,27 @@ +MANAGERS = all + +rtems_tests_PROGRAMS = psxtmthread05 +psxtmthread05_SOURCES = init.c +psxtmthread05_SOURCES += ../../tmtests/include/timesys.h +psxtmthread05_SOURCES += ../../support/src/tmtests_empty_function.c +psxtmthread05_SOURCES += ../../support/src/tmtests_support.c + +dist_rtems_tests_DATA = psxtmthread05.doc + +include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg +include $(top_srcdir)/../automake/compile.am +include $(top_srcdir)/../automake/leaf.am + +OPERATION_COUNT = @OPERATION_COUNT@ +AM_CPPFLAGS += -I$(top_srcdir)/../tmtests/include +AM_CPPFLAGS += -DOPERATION_COUNT=$(OPERATION_COUNT) +AM_CPPFLAGS += -I$(top_srcdir)/../support/include + +LINK_OBJS = $(psxtmthread05_OBJECTS) $(psxtmthread05_LDADD) +LINK_LIBS = $(psxtmthread05_LDLIBS) + +psxtmthread05$(EXEEXT): $(psxtmthread05_OBJECTS) $(psxtmthread05_DEPENDENCIES) + @rm -f psxtmthread05$(EXEEXT) + $(make-exe) + +include $(top_srcdir)/../automake/local.am diff --git a/testsuites/psxtmtests/psxtmthread05/init.c b/testsuites/psxtmtests/psxtmthread05/init.c new file mode 100644 index 0000000..74c30f1 --- /dev/null +++ b/testsuites/psxtmtests/psxtmthread05/init.c @@ -0,0 +1,105 @@ +/* + * COPYRIGHT (c) 1989-2012. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <timesys.h> +#include <pthread.h> +#include <rtems/timerdrv.h> +#include "test_support.h" + +/* forward declarations to avoid warnings */ +void *POSIX_Init(void *argument); +void benchmark_pthread_create(void); +void benchmark_pthread_setschedparam(void); +void *test_thread(void *argument); +void set_thread_priority(pthread_t id, int priority); + +void set_thread_priority(pthread_t id, int priority) +{ + int status; + int policy; + struct sched_param param; + status = pthread_getschedparam(id, &policy, ¶m); + rtems_test_assert( status == 0 ); + param.sched_priority = priority; + benchmark_timer_initialize(); + status = pthread_setschedparam(id, policy, ¶m); + rtems_test_assert( status == 0 ); +} + +void benchmark_pthread_setschedparam(void) +{ + int status; + int priority; + pthread_t thread_ID; + + status = pthread_create(&thread_ID, NULL, test_thread, NULL); + rtems_test_assert( status == 0 ); + priority = 4; + set_thread_priority(thread_ID, priority); +} + +void *test_thread( + void *argument +) +{ + long end_time; + + // XXX we are including thread start time. Need to do something + // XXX that let's it run and voluntarily return. Line + // + test_thread created at 6 + // + POSIX_Init lowers itself to : and switches to test_thread + // + test_thread runs and lowers itself to 4 and switches to POSIX_Init + // + start timer in POSIX_Init + // + POSIX_Init lowers itself to 5 and switches to test_thread + + // XXX moved + end_time = benchmark_timer_read(); + + put_time( + "pthread_setschedparam - lower own priority", + end_time, + 1, /* Only executed once */ + 0, + 0 + ); + + puts( "*** END OF POSIX TIME TEST PSXTMTHREAD05 ***" ); + rtems_test_exit(0); + //Empty thread used in pthread_create(). + return NULL; +} + +void *POSIX_Init( + void *argument +) +{ + + puts( "\n\n*** POSIX TIME TEST PSXTMTHREAD05 ***" ); + benchmark_pthread_setschedparam(); + + rtems_test_assert( 1 ); + return NULL; +} + +/* configuration information */ + +#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER + +#define CONFIGURE_MAXIMUM_POSIX_THREADS 2 +#define CONFIGURE_POSIX_INIT_THREAD_TABLE + +#define CONFIGURE_INIT + +#include <rtems/confdefs.h> +/* end of file */ diff --git a/testsuites/psxtmtests/psxtmthread05/psxtmthread05.doc b/testsuites/psxtmtests/psxtmthread05/psxtmthread05.doc new file mode 100644 index 0000000..304b5b7 --- /dev/null +++ b/testsuites/psxtmtests/psxtmthread05/psxtmthread05.doc @@ -0,0 +1,11 @@ +# COPYRIGHT (c) 1989-2011. +# On-Line Applications Research Corporation (OAR). +# +# The license and distribution terms for this file may be +# found in the file LICENSE in this distribution or at +# http://www.rtems.com/license/LICENSE. +# + +This test benchmarks the following operations: + ++ pthread_setschedparam - lower own priority -- 1.8.4.2
_______________________________________________ rtems-devel mailing list rtems-devel@rtems.org http://www.rtems.org/mailman/listinfo/rtems-devel