Help with debugging a POSIX timing test.

Joel Sherrill joel.sherrill at OARcorp.com
Sun Nov 24 19:05:18 UTC 2013


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.
+ Pay attention to compiler warnings. :)
+ Benchmark time is initialized IMMEDIATELY BEFORE the
single operation under test. We try to avoid including
anything.

I have attached a new version of init.c with comments
hacked in and changes.

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.

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.

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.

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.

--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.sherrill at OARcorp.com        On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
Support Available                (256) 722-9985
-------------- next part --------------
/*
 *  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 benchmark_pthread_setschedparam(void)
{
  int  status;
  int  policy;
  pthread_t thread_ID;
  struct sched_param param;
  param.sched_priority = 5; //XXX: Magic value?
  // JOEL - no.. just an arbtrary priority with numbers above and below it

  status = pthread_create(&thread_ID, NULL, test_thread, NULL);
  rtems_test_assert( status == 0 );
  // Thread creation works
  // Not sure if I should use SCHED_FIFO
  status = pthread_getschedparam(thread_ID, &policy, &param);
  printf("getschedparam: %d\n", status); // Fails with ESRCH, I don't get why though.
  rtems_test_assert( status == 0 );
  // JOEL at POSIX priority 2, internal 253, IDLE=255 (near low end)
  printf("Original priority: %d\n", param.sched_priority);


  param.sched_priority = 4; // JOEL
  printf("Lowered priority: %d\n", param.sched_priority);
  // Ditto, for SCHED_FIFO

  //JOEL ONLY BEFORE THE SINGLE OPERATION BEING TIMED!!
  benchmark_timer_initialize();
  status = pthread_setschedparam(thread_ID, SCHED_FIFO, &param);
  printf("setschedparam: %d\n", status); // Ditto, ESRCH
  rtems_test_assert( status == 0 );
 
}

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 */


More information about the devel mailing list