Changeset 683 for trunk/kernel/kern/alarm.c
- Timestamp:
- Jan 13, 2021, 12:36:17 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/kern/alarm.c
r669 r683 31 31 32 32 //////////////////////////////////////////////////////////////////////////////////////////// 33 // This static function registers the alarm identified ny the <new_alarm> argument33 // This static function registers the alarm identified by the <alarm> & <cxy> arguments 34 34 // in the list of alarms rooted in the core identified by the <core> argument. 35 35 // When the existing list of alarms is not empty, it scan the list to insert the new 36 36 // alarm in the right place to respect the absolute dates ordering. 37 37 //////////////////////////////////////////////////////////////////////////////////////////// 38 // @ new_alarm : local pointer on the new alarm. 39 // @ core : local pointer on the target core. 38 // @ cxy : cluster containing both the new alarm and the core. 39 // @ alarm : local pointer on the alarm. 40 // @ core : local pointer on the core. 40 41 //////////////////////////////////////////////////////////////////////////////////////////// 41 static void alarm_register( alarm_t * new_alarm, 42 static void alarm_register( cxy_t cxy, 43 alarm_t * alarm, 42 44 core_t * core ) 43 45 { 44 list_entry_t * current; // pointer on current list_entry in existing list 45 list_entry_t * previous; // pointer on previous list_entry in existing list 46 alarm_t * current_alarm; // pointer on current alarm in existing list 47 cycle_t current_date; // date of current alarm in existing list 48 49 bool_t done = false; 50 51 // get pointers on root of alarms and lock 46 // get alarm date 47 cycle_t new_date = hal_remote_l64( XPTR( cxy , &alarm->date ) ); 48 49 // build local pointer on root of alarms list 52 50 list_entry_t * root = &core->alarms_root; 53 busylock_t * lock = &core->alarms_lock; 54 55 // get pointer on new_alarm list_entry 56 list_entry_t * new_entry = &new_alarm->list; 57 58 // get new_alarm date 59 cycle_t new_date = new_alarm->date; 60 61 // take the lock 62 busylock_acquire( lock ); 51 52 // build local pointer on new alarm list_entry 53 list_entry_t * new = &alarm->list; 63 54 64 55 // insert new alarm to respect dates order 65 if( list_ is_empty( root ) )// list empty56 if( list_remote_is_empty( cxy , &core->alarms_root ) ) // list empty 66 57 { 67 list_ add_first( root , new_entry);58 list_remote_add_first( cxy , root , new ); 68 59 } 69 else // list non empty60 else // list non empty 70 61 { 71 for( current = root->next ; 72 (current != root) && (done == false) ; 73 current = current->next ) 62 list_entry_t * iter; // local pointer on current list_entry in existing list 63 alarm_t * iter_alarm; // local pointer on current alarm in existing list 64 cycle_t iter_date; // date of current alarm in existing list 65 bool_t done = false; 66 67 for( iter = hal_remote_lpt( XPTR( cxy , &root->next ) ) ; 68 (iter != root) && (done == false) ; 69 iter = hal_remote_lpt( XPTR( cxy , &iter->next ) ) ) 74 70 { 75 // get pointer on previous entry in existing list76 previous = current->pred;77 78 // get pointer on current alarm79 current_alarm = LIST_ELEMENT( current, alarm_t , list );71 // get local pointer on pred and next for iter 72 list_entry_t * prev = hal_remote_lpt( XPTR( cxy , &iter->pred ) ); 73 74 // get local pointer on current alarm 75 iter_alarm = LIST_ELEMENT( iter , alarm_t , list ); 80 76 81 77 // get date for current alarm 82 current_date = current_alarm->date; 83 84 if( current_date > new_date ) // insert new alarm just before current 78 iter_date = hal_remote_l64( XPTR( cxy , &iter_alarm->date ) ); 79 80 // insert new alarm just before current when required 81 if( iter_date > new_date ) 85 82 { 86 new_entry->next = current;87 new_entry->pred = previous;88 89 current->pred = new_entry;90 previous->next = new_entry;83 hal_remote_spt( XPTR( cxy , &new->next ) , iter ); 84 hal_remote_spt( XPTR( cxy , &new->pred ) , prev ); 85 86 hal_remote_spt( XPTR( cxy , &iter->pred ) , new ); 87 hal_remote_spt( XPTR( cxy , &prev->next ) , new ); 91 88 92 89 done = true; … … 96 93 if( done == false ) // new_date is larger than all registered dates 97 94 { 98 list_ add_last( root , new_entry);95 list_remote_add_last( cxy, root , new ); 99 96 } 100 97 } 101 98 } // end alarm_register() 99 100 101 /////////////////////////////////// 102 void alarm_init( alarm_t * alarm ) 103 { 104 alarm->linked = false; 105 list_entry_init( &alarm->list ); 106 } 107 108 /////////////////////////////////////// 109 void alarm_start( xptr_t thread_xp, 110 cycle_t date, 111 void * func_ptr, 112 xptr_t args_xp ) 113 { 114 // get cluster and local pointer on target thread 115 thread_t * tgt_ptr = GET_PTR( thread_xp ); 116 cxy_t tgt_cxy = GET_CXY( thread_xp ); 117 118 // check alarm state 119 assert( __FUNCTION__ , (hal_remote_l32( XPTR(tgt_cxy,&tgt_ptr->alarm.linked)) == false ), 120 "alarm already started"); 121 122 // get local pointer on core running target thread 123 core_t * core = hal_remote_lpt( XPTR( tgt_cxy , &tgt_ptr->core ) ); 124 125 // build extended pointer on lock protecting alarms list 126 xptr_t lock_xp = XPTR( tgt_cxy , &core->alarms_lock ); 127 128 // initialize alarm descriptor 129 hal_remote_s64( XPTR( tgt_cxy , &tgt_ptr->alarm.date ) , date ); 130 hal_remote_spt( XPTR( tgt_cxy , &tgt_ptr->alarm.func_ptr ) , func_ptr ); 131 hal_remote_s64( XPTR( tgt_cxy , &tgt_ptr->alarm.args_xp ) , args_xp ); 132 hal_remote_s32( XPTR( tgt_cxy , &tgt_ptr->alarm.linked ) , true ); 133 134 // take the lock 135 remote_busylock_acquire( lock_xp ); 136 137 // register alarm in core list 138 alarm_register( tgt_cxy , &tgt_ptr->alarm , core ); 139 140 //release the lock 141 remote_busylock_release( lock_xp ); 142 143 } // end alarm_start() 144 145 146 ///////////////////////////////////// 147 void alarm_stop( xptr_t thread_xp ) 148 { 149 // get cluster and local pointer on target thread 150 thread_t * tgt_ptr = GET_PTR( thread_xp ); 151 cxy_t tgt_cxy = GET_CXY( thread_xp ); 152 153 // get local pointer on core running target thread 154 core_t * core = hal_remote_lpt( XPTR( tgt_cxy , &tgt_ptr->core ) ); 155 156 // build extended pointer on lock protecting alarms list 157 xptr_t lock_xp = XPTR( tgt_cxy , &core->alarms_lock ); 158 159 // take the lock 160 remote_busylock_acquire( lock_xp ); 161 162 // unlink the alarm from the list rooted in core 163 list_remote_unlink( tgt_cxy , &tgt_ptr->alarm.list ); 164 165 // update alarm state 166 hal_remote_s32( XPTR( tgt_cxy , &tgt_ptr->alarm.linked ) , false ); 167 168 //release the lock 169 remote_busylock_release( lock_xp ); 170 171 } // end alarm_stop() 172 173 174 ////////////////////////////////////// 175 void alarm_update( xptr_t thread_xp, 176 cycle_t new_date ) 177 { 178 // get cluster and local pointer on target thread 179 thread_t * tgt_ptr = GET_PTR( thread_xp ); 180 cxy_t tgt_cxy = GET_CXY( thread_xp ); 181 182 // get local pointer on core running target thread 183 core_t * core = hal_remote_lpt( XPTR( tgt_cxy , &tgt_ptr->core ) ); 184 185 // build extended pointer on lock protecting alarms list 186 xptr_t lock_xp = XPTR( tgt_cxy , &core->alarms_lock ); 187 188 // take the lock 189 remote_busylock_acquire( lock_xp ); 190 191 // unlink the alarm from the core list 192 list_remote_unlink( tgt_cxy , &tgt_ptr->alarm.list ); 193 194 // update the alarm date and state 195 hal_remote_s64( XPTR( tgt_cxy , &tgt_ptr->alarm.date ) , new_date ); 196 hal_remote_s32( XPTR( tgt_cxy , &tgt_ptr->alarm.linked ) , true ); 197 198 // register alarm in core list 199 alarm_register( tgt_cxy , &tgt_ptr->alarm , core ); 200 102 201 // release the lock 103 busylock_release( lock ); 104 105 } // end alarm_register() 106 107 ////////////////////////////////////// 108 void alarm_start( cycle_t date, 109 void * func_ptr, 110 xptr_t args_xp, 111 thread_t * thread ) 112 { 113 // get pointer on alarm 114 alarm_t * alarm = &thread->alarm; 115 116 // initialize alarm descriptor 117 alarm->date = date; 118 alarm->func_ptr = func_ptr; 119 alarm->args_xp = args_xp; 120 121 // register alarm in core list 122 alarm_register( alarm , thread->core ); 123 124 } // end alarm_start() 125 126 ///////////////////////////////////// 127 void alarm_update( thread_t * thread, 128 cycle_t new_date ) 129 { 130 // get pointer on alarm 131 alarm_t * alarm = &thread->alarm; 132 133 // get pointer on core 134 core_t * core = thread->core; 135 136 // get pointer on lock protecting the alarms list 137 busylock_t * lock = &core->alarms_lock; 138 139 // unlink the alarm from the core list 140 busylock_acquire( lock ); 141 list_unlink( &alarm->list ); 142 busylock_release( lock ); 143 144 // update the alarm date 145 alarm->date = new_date; 146 147 // register alarm in core list 148 alarm_register( alarm , core ); 149 202 remote_busylock_release( lock_xp ); 203 150 204 } // end alarm_update() 151 205 152 //////////////////////////////////// 153 void alarm_stop( thread_t * thread ) 154 { 155 // get pointer on alarm 156 alarm_t * alarm = &thread->alarm; 157 158 // get pointer on core 159 core_t * core = thread->core; 160 161 // get pointer on lock protecting the alarms list 162 busylock_t * lock = &core->alarms_lock; 163 164 // unlink the alarm from the list rooted in core 165 busylock_acquire( lock ); 166 list_unlink( &alarm->list ); 167 busylock_release( lock ); 168 169 } // end alarm_stop() 170 206
Note: See TracChangeset
for help on using the changeset viewer.