Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
NuttX RTOS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
f4grx
NuttX RTOS
Commits
84533434
Commit
84533434
authored
8 years ago
by
Gregory Nutt
Browse files
Options
Downloads
Patches
Plain Diff
scheduler instrumentation: Add a little more protection for the SMP case
parent
b29b7753
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sched/sched/sched_note.c
+34
-6
34 additions, 6 deletions
sched/sched/sched_note.c
with
34 additions
and
6 deletions
sched/sched/sched_note.c
+
34
−
6
View file @
84533434
...
...
@@ -63,8 +63,8 @@
struct
note_info_s
{
unsigned
int
ni_head
;
unsigned
int
ni_tail
;
volatile
unsigned
int
ni_head
;
volatile
unsigned
int
ni_tail
;
uint8_t
ni_buffer
[
CONFIG_SCHED_NOTE_BUFSIZE
];
};
...
...
@@ -281,6 +281,7 @@ static void note_add(FAR const uint8_t *note, uint8_t notelen)
{
unsigned
int
head
;
unsigned
int
next
;
unsigned
int
nxthd
;
#ifdef CONFIG_SMP
/* Ignore notes that are not in the set of monitored CPUs */
...
...
@@ -293,10 +294,37 @@ static void note_add(FAR const uint8_t *note, uint8_t notelen)
}
#endif
/* Get the index to the head of the circular buffer */
DEBUGASSERT
(
note
!=
NULL
&&
notelen
<
CONFIG_SCHED_NOTE_BUFSIZE
);
head
=
g_note_info
.
ni_head
;
do
{
/* Get the index to the head of the circular buffer */
head
=
g_note_info
.
ni_head
;
/* Pre-calculate the next head index. We do this in advance to
* protect note as it is written. In the single CPU case, this is not
* a problem because this logic is always called within a critical
* section, but in the SMP case we have less protection. pre-
* calculating the next head indexed does not eliminate all
* possibility of conflict; it is possible that one note could be lost
* or corrupted. But the integrity of the overal buffer should be
* retained.
*/
nxthd
=
note_next
(
head
,
notelen
);
/* Write the next head. There are two possible race conditions: (1)
* some other CPU wrote the head after we fetched it above. That
* note from the other CPU will be lost (and this one may be
* corrupted), or (2) some other CPU will write the head after we
* write it and the write the same value. Again, one note will be
* lost or corrupted.
*/
g_note_info
.
ni_head
=
nxthd
;
}
while
(
nxthd
!=
g_note_info
.
ni_head
);
/* Loop until all bytes have been transferred to the circular buffer */
...
...
@@ -322,7 +350,7 @@ static void note_add(FAR const uint8_t *note, uint8_t notelen)
notelen
--
;
}
g_note_info
.
ni_head
=
head
;
DEBUGASSERT
(
head
==
nxthd
)
;
}
/****************************************************************************
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment