RTEMS
watchdogtick.c
1 /*
2  * Copyright (c) 2015, 2016 embedded brains GmbH. All rights reserved.
3  *
4  * embedded brains GmbH
5  * Dornierstr. 4
6  * 82178 Puchheim
7  * Germany
8  * <rtems@embedded-brains.de>
9  *
10  * The license and distribution terms for this file may be
11  * found in the file LICENSE in this distribution or at
12  * http://www.rtems.org/license/LICENSE.
13  */
14 
15 #ifdef HAVE_CONFIG_H
16 #include "config.h"
17 #endif
18 
23 
25  Watchdog_Header *header,
26  Watchdog_Control *first,
27  uint64_t now,
28 #ifdef RTEMS_SMP
29  ISR_lock_Control *lock,
30 #endif
31  ISR_lock_Context *lock_context
32 )
33 {
34  do {
35  if ( first->expire <= now ) {
37 
38  _Watchdog_Next_first( header, first );
39  _RBTree_Extract( &header->Watchdogs, &first->Node.RBTree );
41  routine = first->routine;
42 
43  _ISR_lock_Release_and_ISR_enable( lock, lock_context );
44  ( *routine )( first );
45  _ISR_lock_ISR_disable_and_acquire( lock, lock_context );
46  } else {
47  break;
48  }
49 
50  first = _Watchdog_Header_first( header );
51  } while ( first != NULL );
52 }
53 
55 {
56  ISR_lock_Context lock_context;
57  Watchdog_Header *header;
58  Watchdog_Control *first;
59  uint64_t ticks;
60  struct timespec now;
61 
62  if ( _Per_CPU_Is_boot_processor( cpu ) ) {
64  }
65 
66  _ISR_lock_ISR_disable_and_acquire( &cpu->Watchdog.Lock, &lock_context );
67 
68  ticks = cpu->Watchdog.ticks;
69  _Assert( ticks < UINT64_MAX );
70  ++ticks;
71  cpu->Watchdog.ticks = ticks;
72 
73  header = &cpu->Watchdog.Header[ PER_CPU_WATCHDOG_TICKS ];
74  first = _Watchdog_Header_first( header );
75 
76  if ( first != NULL ) {
77  _Watchdog_Tickle(
78  header,
79  first,
80  ticks,
81  &cpu->Watchdog.Lock,
82  &lock_context
83  );
84  }
85 
86  header = &cpu->Watchdog.Header[ PER_CPU_WATCHDOG_MONOTONIC ];
87  first = _Watchdog_Header_first( header );
88 
89  if ( first != NULL ) {
91  _Watchdog_Tickle(
92  header,
93  first,
95  &cpu->Watchdog.Lock,
96  &lock_context
97  );
98  }
99 
100  header = &cpu->Watchdog.Header[ PER_CPU_WATCHDOG_REALTIME ];
101  first = _Watchdog_Header_first( header );
102 
103  if ( first != NULL ) {
104  _Timecounter_Getnanotime( &now );
105  _Watchdog_Tickle(
106  header,
107  first,
109  &cpu->Watchdog.Lock,
110  &lock_context
111  );
112  }
113 
114  _ISR_lock_Release_and_ISR_enable( &cpu->Watchdog.Lock, &lock_context );
115 
116  _Scheduler_Tick( cpu );
117 }
union Watchdog_Control::@33 Node
Nodes for the watchdog.
Watchdog_Service_routine(* Watchdog_Service_routine_entry)(Watchdog_Control *)
Pointer to a watchdog service routine.
Definition: watchdog.h:66
Index for realtime clock per-CPU watchdog header.
Definition: percpu.h:325
void _Timecounter_Getnanotime(struct timespec *ts)
Returns the wall clock time in the timespec format.
The watchdog is inactive.
Definition: watchdogimpl.h:61
#define _ISR_lock_Release_and_ISR_enable(_lock, _context)
Releases an ISR lock.
Definition: isrlock.h:257
Watchdog_Header Header[PER_CPU_WATCHDOG_COUNT]
Header for watchdogs.
Definition: percpu.h:474
static __inline__ void _Watchdog_Next_first(Watchdog_Header *header, Watchdog_Control *the_watchdog)
Sets the first node of the header.
Definition: watchdogimpl.h:366
ISR_lock_Control Lock
This lock protects some members of this structure.
Definition: percpu.h:481
static __inline__ uint64_t _Watchdog_Ticks_from_timespec(const struct timespec *ts)
Converts the timespec in ticks.
Definition: watchdogimpl.h:522
Inlined Routines in the Watchdog Handler.
uint64_t expire
This field is the expiration time point.
Definition: watchdog.h:117
uint64_t ticks
Protects all watchdog operations on this processor.
Definition: percpu.h:467
Inlined Routines Associated with the Manipulation of the Scheduler.
Constants and Structures Related with Thread Dispatch.
The control block used to manage each watchdog timer.
Definition: watchdog.h:90
ISR lock control.
Definition: isrlock.h:56
Watchdog_Service_routine_entry routine
This field is the function to invoke.
Definition: watchdog.h:114
RBTree_Control Watchdogs
Red-black tree of scheduled watchdogs sorted by expiration time.
Definition: watchdog.h:75
static __inline__ void _Scheduler_Tick(const Per_CPU_Control *cpu)
Scheduler method invoked at each clock tick.
RBTree_Node RBTree
this field is a red-black tree node structure and allows this to be placed on a red-black tree used t...
Definition: watchdog.h:99
Per CPU Core Structure.
Definition: percpu.h:347
struct Per_CPU_Control::@13 Watchdog
Watchdog state for this processor.
void _Timecounter_Getnanouptime(struct timespec *ts)
Returns the uptime in the timespec format.
#define _ISR_lock_ISR_disable_and_acquire(_lock, _context)
Acquires an ISR lock.
Definition: isrlock.h:232
void _Watchdog_Do_tickle(Watchdog_Header *header, Watchdog_Control *first, uint64_t now, ISR_lock_Control *lock, ISR_lock_Context *lock_context)
Calls the routine of each not expired watchdog control node.
Definition: watchdogtick.c:24
static __inline__ Watchdog_Control * _Watchdog_Header_first(const Watchdog_Header *header)
Returns the first of the watchdog header.
Definition: watchdogimpl.h:115
The watchdog header to manage scheduled watchdogs.
Definition: watchdog.h:71
Index for monotonic clock per-CPU watchdog header.
Definition: percpu.h:334
void _RBTree_Extract(RBTree_Control *the_rbtree, RBTree_Node *the_node)
Extracts (removes) the node from the red-black tree.
Definition: rbtreeextract.c:35
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65
Index for tick clock per-CPU watchdog header.
Definition: percpu.h:316
volatile Watchdog_Interval _Watchdog_Ticks_since_boot
The watchdog ticks counter.
static __inline__ void _Watchdog_Set_state(Watchdog_Control *the_watchdog, Watchdog_State state)
Sets the state of the watchdog.
Definition: watchdogimpl.h:162
Timecounter API.
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG.
Definition: assert.h:100
void _Watchdog_Tick(Per_CPU_Control *cpu)
Performs a watchdog tick.
Definition: watchdogtick.c:54