//----------------------------------------------------------------------------------- //void put_data_info : hien thi thong tin thu ngay thang tren lcd //input: gia tri gio phut giay //output: none void put_time_info() { lcd_gotoxy(0,0); lcd_puts(" "); put_time(hour,4,0); lcd_putchar(':'); put_time(minute,7,0); lcd_putchar(':'); put_time(second,10,0); lcd_gotoxy(12,0); lcd_puts(" "); }
rtems_task Task_2( rtems_task_argument argument ) { #if defined(RTEMS_SMP) rtems_interrupt_level level; #endif Chain_Control *ready_queues; #if (MUST_WAIT_FOR_INTERRUPT == 1) while ( Interrupt_occurred == 0 ); #endif end_time = benchmark_timer_read(); put_time( "rtems interrupt: entry overhead returns to preempting task", Interrupt_enter_time, 1, 0, timer_overhead ); put_time( "rtems interrupt: exit overhead returns to preempting task", end_time, 1, 0, 0 ); fflush( stdout ); /* * Switch back to the other task to exit the test. */ #if defined(RTEMS_SMP) rtems_interrupt_disable(level); #endif ready_queues = (Chain_Control *) _Scheduler.information; _Thread_Executing = (Thread_Control *) _Chain_First(&ready_queues[LOW_PRIORITY]); _Thread_Dispatch_necessary = 1; #if defined(RTEMS_SMP) rtems_interrupt_enable(level); #endif _Thread_Dispatch(); }
rtems_task Task_1( rtems_task_argument argument ) { rtems_status_code status; benchmark_timer_initialize(); (void) rtems_signal_catch( Process_asr_for_pass_1, RTEMS_DEFAULT_MODES ); end_time = benchmark_timer_read(); put_time( "rtems_signal_catch", end_time, 1, 0, CALLING_OVERHEAD_SIGNAL_CATCH ); benchmark_timer_initialize(); rtems_signal_send( Task_id[ 2 ], 1 ); end_time = benchmark_timer_read(); put_time( "rtems_signal_send: returns to caller", end_time, 1, 0, CALLING_OVERHEAD_SIGNAL_SEND ); benchmark_timer_initialize(); (void) rtems_signal_send( RTEMS_SELF, RTEMS_SIGNAL_1 ); /* end time is done is RTEMS_ASR */ end_time = benchmark_timer_read(); put_time( "exit ASR overhead: returns to calling task", end_time, 1, 0, 0 ); status = rtems_signal_catch( Process_asr_for_pass_2, RTEMS_NO_PREEMPT ); directive_failed( status, "rtems_signal_catch" ); benchmark_timer_initialize(); (void) rtems_signal_send( RTEMS_SELF, RTEMS_SIGNAL_1 ); }
rtems_task Task_2( rtems_task_argument argument ) { Thread_Control *executing = _Thread_Get_executing(); Scheduler_priority_Context *scheduler_context = _Scheduler_priority_Get_context( _Scheduler_Get( executing ) ); ISR_lock_Context lock_context; #if (MUST_WAIT_FOR_INTERRUPT == 1) while ( Interrupt_occurred == 0 ); #endif end_time = benchmark_timer_read(); put_time( "rtems interrupt: entry overhead returns to preempting task", Interrupt_enter_time, 1, 0, timer_overhead ); put_time( "rtems interrupt: exit overhead returns to preempting task", end_time, 1, 0, 0 ); fflush( stdout ); /* * Switch back to the other task to exit the test. */ _Scheduler_Acquire( executing, &lock_context ); _Thread_Executing = (Thread_Control *) _Chain_First(&scheduler_context->Ready[LOW_PRIORITY]); _Thread_Dispatch_necessary = 1; _Scheduler_Release( executing, &lock_context ); _Thread_Dispatch(); }
void *Low( void *argument ) { int status; benchmark_timer_t end_time; /* write locking */ status = pthread_rwlock_wrlock(&rwlock); end_time = benchmark_timer_read(); rtems_test_assert( status == 0 ); put_time( "pthread_rwlock_unlock: thread waiting preempt", end_time, OPERATION_COUNT, 0, 0 ); TEST_END(); rtems_test_exit( 0 ); return NULL; }
void *Blocker( void *argument ) { uint32_t end_time; struct sched_param param; int policy; int status; status = pthread_mutex_lock(&MutexID); rtems_test_assert( status == 0 ); status = pthread_getschedparam(pthread_self(), &policy, ¶m); rtems_test_assert( status == 0 ); param.sched_priority = sched_get_priority_max(policy) - 1; status = pthread_setschedparam(pthread_self(), policy, ¶m); /* Thread blocks, unlocks mutex, waits for CondID to be signaled */ pthread_cond_wait(&CondID,&MutexID); /* Once signaled, this thread preempts POSIX_Init thread */ end_time = benchmark_timer_read(); put_time( "pthread_cond_signal: thread waiting preempt", end_time, 1, 0, 0 ); TEST_END(); rtems_test_exit( 0 ); return NULL; }
void rtems_time_test_measure_operation( const char *description, rtems_time_test_method_t operation, void *argument, int iterations, int overhead ) { int i; uint32_t loop_overhead; uint32_t end_time; benchmark_timer_initialize(); for (i=0 ; i<iterations ; i++ ) { benchmark_timer_empty_operation( i, argument ); } loop_overhead = benchmark_timer_read(); benchmark_timer_initialize(); for (i=0 ; i<iterations ; i++ ) { (*operation)( i, argument ); } end_time = benchmark_timer_read(); put_time( description, end_time, iterations, loop_overhead, overhead ); }
rtems_task High_task( rtems_task_argument argument ) { int index; benchmark_timer_initialize(); for ( index=1 ; index < operation_count ; index++ ) (void) benchmark_timer_empty_function(); overhead = benchmark_timer_read(); benchmark_timer_initialize(); for ( index=1 ; index <= operation_count ; index++ ) (void) rtems_message_queue_urgent( Queue_id, Buffer, MESSAGE_SIZE ); end_time = benchmark_timer_read(); put_time( "rtems_message_queue_urgent: task readied returns to caller", end_time, operation_count, overhead, 0 ); TEST_END(); rtems_test_exit( 0 ); }
void *Low( void *argument ) { int status; benchmark_timer_t end_time; /* write locking */ status = pthread_rwlock_wrlock(&rwlock); end_time = benchmark_timer_read(); rtems_test_assert( status == 0 ); put_time( "pthread_rwlock_unlock - thread waiting, preempt", end_time, OPERATION_COUNT, 0, 0 ); puts( "*** END OF POSIX TIME TEST PSXTMRWLOCK 07 ***" ); rtems_test_exit( 0 ); return NULL; }
rtems_task High_task( rtems_task_argument argument ) { size_t size; (void) rtems_message_queue_receive( Queue_id, (long (*)[4]) Buffer, &size, RTEMS_DEFAULT_OPTIONS, RTEMS_NO_TIMEOUT ); end_time = benchmark_timer_read(); put_time( "rtems_message_queue_send: task readied preempts caller", end_time, operation_count, 0, 0 ); TEST_END(); rtems_test_exit( 0 ); }
rtems_task High_task( rtems_task_argument argument ) { uint32_t count; rtems_status_code status; benchmark_timer_initialize(); (void) rtems_message_queue_broadcast( Queue_id, Buffer, MESSAGE_SIZE, &count ); end_time = benchmark_timer_read(); put_time( "rtems_message_queue_broadcast: task readied -- returns to caller", end_time, 1, 0, CALLING_OVERHEAD_MESSAGE_QUEUE_BROADCAST ); status = rtems_task_suspend(RTEMS_SELF); directive_failed( status, "rtems_task_suspend" ); }
void *Low( void *argument ) { benchmark_timer_t end_time; /* * Now we have finished the thread startup overhead, * so let other threads run. When we return, we can * finish the benchmark. */ sched_yield(); /* let other threads run */ end_time = benchmark_timer_read(); put_time( "pthread_exit", end_time, OPERATION_COUNT, 0, 0 ); puts( "*** END OF POSIX TIME TEST PSXTMTHREAD03 ***" ); rtems_test_exit( 0 ); return NULL; }
rtems_task Task02( rtems_task_argument ignored ) { /* Benchmark code */ benchmark_timer_initialize(); for ( count = 0; count < BENCHMARKS; count++ ) { if ( sem_exe == 1 ) { rtems_semaphore_obtain( sem_id, RTEMS_WAIT, 0 ); } rtems_task_wake_after( RTEMS_YIELD_PROCESSOR ); if ( sem_exe == 1 ) { rtems_semaphore_release( sem_id ); } rtems_task_wake_after( RTEMS_YIELD_PROCESSOR ); } telapsed = benchmark_timer_read(); /* Check which run this was */ if (sem_exe == 0) { tswitch_overhead = telapsed; rtems_task_suspend( Task_id[0] ); rtems_task_suspend( RTEMS_SELF ); } else { put_time( "Rhealstone: Semaphore Shuffle", telapsed, (BENCHMARKS * 2), /* Total number of semaphore-shuffles*/ tswitch_overhead, /* Overhead of loop and task switches */ 0 ); TEST_END(); rtems_test_exit( 0 ); } }
rtems_task High_task( rtems_task_argument argument ) { int index; benchmark_timer_initialize(); for ( index=1 ; index < operation_count ; index++ ) (void) benchmark_timer_empty_function(); overhead = benchmark_timer_read(); benchmark_timer_initialize(); for ( index=1 ; index < operation_count ; index++ ) (void) rtems_message_queue_send( Queue_id, Buffer, MESSAGE_SIZE ); end_time = benchmark_timer_read(); put_time( "rtems_message_queue_send: task readied -- returns to caller", end_time, operation_count - 1, overhead, CALLING_OVERHEAD_MESSAGE_QUEUE_SEND ); puts( "*** END OF TEST 12 ***" ); rtems_test_exit( 0 ); }
void *Low( void *argument ) { uint32_t end_time; /* * Now we have finished the thread startup overhead, * so let other threads run. When we return, we can * finish the benchmark. */ sched_yield(); /* let other threads run */ end_time = benchmark_timer_read(); put_time( "pthread_rwlock_rdlock - not available, blocks", end_time, OPERATION_COUNT, 0, 0 ); puts( "*** END OF POSIX TIME PSXTMRWLOCK 02 TEST ***" ); rtems_test_exit( 0 ); return NULL; }
int main(void) { printf("現在は"); put_time(); printf("です。\n"); return 0; }
void *Low( void *argument ) { benchmark_timer_t end_time; /* * Now we have finished the thread startup overhead, * so let other threads run. When we return, we can * finish the benchmark. */ sched_yield(); /* let other threads run */ end_time = benchmark_timer_read(); put_time( "pthread_mutex_lock: unavailable block", end_time, OPERATION_COUNT, 0, 0 ); TEST_END(); rtems_test_exit( 0 ); return NULL; }
static void benchmark_mq_timedreceive(void) { benchmark_timer_t end_time; int status; unsigned int priority; struct timespec timeout; int message[MQ_MAXMSG]; priority = 1; /*priority low*/ timeout.tv_sec = 0; timeout.tv_nsec = 0; benchmark_timer_initialize(); status = mq_timedreceive( queue2, ( char *)message, MQ_MSGSIZE, &priority, &timeout); end_time = benchmark_timer_read(); rtems_test_assert( status != (-1) ); put_time( "mq_timedreceive: available", end_time, 1, /* Only executed once */ 0, 0 ); }
rtems_task High_task( rtems_task_argument argument ) { size_t size; (void) rtems_message_queue_receive( Queue_id, (long (*)[4]) Buffer, &size, RTEMS_DEFAULT_OPTIONS, RTEMS_NO_TIMEOUT ); end_time = benchmark_timer_read(); put_time( "rtems_message_queue_urgent: task readied -- preempts caller", end_time, operation_count, 0, CALLING_OVERHEAD_MESSAGE_QUEUE_URGENT ); puts( "*** END OF TEST 13 ***" ); rtems_test_exit( 0 ); }
static void benchmark_pthread_barrier_init(void) { benchmark_timer_t end_time; int status; pthread_barrierattr_t attr; /* initialize attr with default attributes * for all of the attributes defined by the implementation */ status = pthread_barrierattr_init( &attr ); rtems_test_assert( status == 0 ); benchmark_timer_initialize(); status = pthread_barrier_init( &barrier,&attr, 1 ); end_time = benchmark_timer_read(); rtems_test_assert( status == 0 ); put_time( "pthread_barrier_init", end_time, 1, /* Only executed once */ 0, 0 ); }
void benchmark_pthread_setschedparam(void) { uint32_t end_time; int status; int policy; struct sched_param param; status = pthread_getschedparam( pthread_self(), &policy, ¶m ); rtems_test_assert( status == 0 ); /* Arbitrary priority, no other threads to preempt us so it doesn't matter. */ param.sched_priority = 5; benchmark_timer_initialize(); status = pthread_setschedparam( pthread_self(), policy, ¶m ); end_time = benchmark_timer_read(); rtems_test_assert( status == 0 ); put_time( "pthread_setschedparam: no thread switch", end_time, 1, /* Only executed once */ 0, 0 ); }
//----------------------------------------------------------------------------------- //void put_data_info : hien thi thong tin thu ngay thang tren lcd //input: none //output: none void put_date_info() { lcd_gotoxy(0,1); lcd_puts(" "); switch(day) { // neu la chu nhat case 1: lcd_puts("CN "); break; // neu la thu 2 case 2: lcd_puts("T2 "); break; //neu la thu 3 case 3: lcd_puts("T3 "); break; // neu la thu 4 case 4: lcd_puts("T4 "); break; // neu la thu 5 case 5: lcd_puts("T5 "); break; // neu la thu 6 case 6: lcd_puts("T6 "); break; // neu la thu 7 case 7: lcd_puts("T7 "); break; // neu khong co truong hop nao thi out default: break; } put_time(date,4,1); lcd_putchar('-'); put_time(month,7,1); lcd_putchar('-'); lcd_gotoxy(10,1); lcd_puts("20 "); put_time(year,12,1); }
std::string timestampToLocalString(const Timepoint& timestamp) { const time_t time = std::chrono::system_clock::to_time_t(timestamp); std::stringstream ss; struct tm ptime; localtime_r(&time, &ptime); ss << put_time(&ptime, "%Y-%m-%dT%H:%M:%S"); return ss.str(); }
void *POSIX_Init( void *argument ) { int status; pthread_t threadId; benchmark_timer_t end_time; pthread_rwlockattr_t attr; TEST_BEGIN(); status = pthread_create( &threadId, NULL, Blocker, NULL ); rtems_test_assert( status == 0 ); /* * Deliberately create the rwlock after the threads. This way if the * threads do run before we intend, they will get an error. */ /* creating rwlock */ status = pthread_rwlockattr_init( &attr ); rtems_test_assert( status == 0 ); status = pthread_rwlock_init( &rwlock, &attr ); rtems_test_assert( status == 0 ); /* * Ensure the rwlock is unavailable so the other threads block. */ /* lock rwlock to ensure thread blocks */ status = pthread_rwlock_wrlock(&rwlock); rtems_test_assert( status == 0 ); /* * Let the other thread start so the thread startup overhead, * is accounted for. When we return, we can start the benchmark. */ sched_yield(); /* let other thread run */ benchmark_timer_initialize(); status = pthread_rwlock_unlock(&rwlock); /* unlock the rwlock */ end_time = benchmark_timer_read(); rtems_test_assert( status == 0 ); put_time( "pthread_rwlock_unlock: thread waiting no preempt", end_time, 1, 0, 0 ); TEST_END(); rtems_test_exit( 0 ); return NULL; }
void *POSIX_Init( void *argument ) { int status; pthread_t threadId; uint32_t end_time; struct sched_param param; int policy; TEST_BEGIN(); status = pthread_create( &threadId, NULL, Blocker, NULL ); rtems_test_assert( status == 0 ); status = pthread_mutex_init(&MutexID, NULL); rtems_test_assert( status == 0 ); status = pthread_cond_init(&CondID, NULL); /* Create condition variable */ rtems_test_assert( status == 0 ); /* * Let the other thread start so the thread startup overhead, * is accounted for. When we return, we can start the benchmark. */ sched_yield(); /* let other thread run */ /* To be extra sure we don't get preempted on the signal */ status = pthread_getschedparam(pthread_self(), &policy, ¶m); rtems_test_assert( status == 0); param.sched_priority = sched_get_priority_max(policy) - 1; status = pthread_setschedparam(pthread_self(), policy, ¶m); rtems_test_assert( status == 0); benchmark_timer_initialize(); status = pthread_cond_signal(&CondID); end_time = benchmark_timer_read(); rtems_test_assert( status == 0 ); put_time( "pthread_cond_signal: thread waiting no preempt", end_time, 1, 0, 0 ); TEST_END(); rtems_test_exit( 0 ); return NULL; }
rtems_task Task_2( rtems_task_argument argument ) { #if (MUST_WAIT_FOR_INTERRUPT == 1) while ( Interrupt_occurred == 0 ); #endif end_time = Timer_read(); put_time( "interrupt entry overhead: returns to preempting task", Interrupt_enter_time, 1, 0, timer_overhead ); put_time( "interrupt exit overhead: returns to preempting task", end_time, 1, 0, 0 ); fflush( stdout ); /* * Switch back to the other task to exit the test. */ _Thread_Dispatch_disable_level = 0; _Thread_Heir = (rtems_tcb *) _Thread_Ready_chain[254].first; _Context_Switch_necessary = 1; _Thread_Dispatch(); }
rtems_task Test_task ( rtems_task_argument argument ) { benchmark_timer_initialize(); rtems_message_queue_create( 1, OPERATION_COUNT, MESSAGE_SIZE, RTEMS_DEFAULT_ATTRIBUTES, &Queue_id ); end_time = benchmark_timer_read(); put_time( "rtems_message_queue_create: only case", end_time, 1, 0, CALLING_OVERHEAD_MESSAGE_QUEUE_CREATE ); queue_test(); benchmark_timer_initialize(); rtems_message_queue_delete( Queue_id ); end_time = benchmark_timer_read(); put_time( "rtems_message_queue_delete: only case", end_time, 1, 0, CALLING_OVERHEAD_MESSAGE_QUEUE_DELETE ); TEST_END(); rtems_test_exit( 0 ); }
void *POSIX_Init( void *argument ) { int status; pthread_t threadId; benchmark_timer_t end_time; puts( "\n\n*** POSIX TIME TEST PSXTMMUTEX05 ***" ); status = pthread_create( &threadId, NULL, Blocker, NULL ); rtems_test_assert( status == 0 ); /* * Deliberately create the mutex after the threads. This way if the * threads do run before we intend, they will get an error. */ status = pthread_mutex_init( &MutexId, NULL ); rtems_test_assert( status == 0 ); /* * Ensure the mutex is unavailable so the other threads block. */ status = pthread_mutex_lock( &MutexId ); rtems_test_assert( status == 0 ); /* * Let the other thread start so the thread startup overhead, * is accounted for. When we return, we can start the benchmark. */ sched_yield(); /* let other thread run */ benchmark_timer_initialize(); status = pthread_mutex_unlock( &MutexId ); end_time = benchmark_timer_read(); rtems_test_assert( status == 0 ); put_time( "pthread_mutex_unlock - unblocking, no preemption", end_time, 1, 0, 0 ); puts( "*** END OF POSIX TIME TEST PSXTMMUTEX05 ***" ); rtems_test_exit( 0 ); return NULL; }
void *POSIX_Init( void *argument ) { int status; pthread_t threadId; long end_time; puts( "\n\n*** POSIX TIME TEST @UPPER@ ***" ); status = pthread_create( &threadId, NULL, Blocker, NULL ); rtems_test_assert( status == 0 ); /* * Deliberately create the XXX after the threads. This way if the * threads do run before we intend, they will get an error. */ status = 0; /* XXX create resource */ rtems_test_assert( status == 0 ); /* * Ensure the mutex is unavailable so the other threads block. */ status = 0; /* XXX lock resource to ensure thread blocks */ rtems_test_assert( status == 0 ); /* * Let the other thread start so the thread startup overhead, * is accounted for. When we return, we can start the benchmark. */ sched_yield(); /* let other thread run */ benchmark_timer_initialize(); status = 0; /* XXX unblocking operation goes here */ end_time = benchmark_timer_read(); rtems_test_assert( status == 0 ); put_time( "@DESC", end_time, 1, 0, 0 ); puts( "*** END OF POSIX TIME TEST @UPPER@ ***" ); rtems_test_exit( 0 ); return NULL; }
void *POSIX_Init(void *argument) { int status; pthread_t threadId; benchmark_timer_t end_time; TEST_BEGIN(); status = pthread_create( &threadId, NULL, Blocker, NULL ); rtems_test_assert( status == 0 ); /* * Deliberately create the semaphore after the threads. This way if the * threads do run before we intend, they will get an error. */ status = sem_init( &sem1, 0, 1 ); rtems_test_assert( status == 0 ); /* * Ensure the semaphore is unavailable so the other threads block. * Lock semaphore resource to ensure thread blocks. */ status = sem_wait(&sem1); rtems_test_assert( status == 0 ); /* * Let the other thread start so the thread startup overhead, * is accounted for. When we return, we can start the benchmark. */ sched_yield(); /* let other thread run */ benchmark_timer_initialize(); status = sem_post( &sem1 ); /* semaphore unblocking operation */ end_time = benchmark_timer_read(); rtems_test_assert( status == 0 ); put_time( "sem_post: thread waiting no preempt", end_time, 1, 0, 0 ); TEST_END(); rtems_test_exit( 0 ); return NULL; }