-
Notifications
You must be signed in to change notification settings - Fork 513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Diagnostics service #1390
Diagnostics service #1390
Conversation
@@ -1 +1,4 @@ | |||
#include "../../../../hal/src/stm32/newlib.cpp" | |||
|
|||
// Defining this in hal/src/stm32/newlib.cpp causes linker errors | |||
void *__dso_handle = NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know what has changed to make this necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
part1
now has a global variable (Diagnostics
) with a non-trivial destructor
services/inc/diagnostics.h
Outdated
typedef void(*diag_enum_sources_callback)(const diag_source* src, void* data); | ||
|
||
typedef struct diag_source { | ||
size_t size; // Size of this structure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we make size
a 16 bit quantity so it packs nicely into memory better? Oh I see it already does. Maybe add another uint16_t reserved
so we can make use of those 16-bits and keep the padding alignment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
services/src/diagnostics.cpp
Outdated
class Diagnostics { | ||
public: | ||
Diagnostics() : | ||
enabled_(0) { // The service is disabled initially |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the rationale for having enable/disable for the service? If it's to save expensive computation then perhaps we should move the enable flag to the diag_source?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rationale is to avoid a race condition, which is possible when the system receives a request or a call querying diagnostic data but data sources are still being registered. The system explicitly enables the diagnostic service after invoking all global constructors in all system parts here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, that makes sense. The name enabled
is slightly counter-intuitive and that you cannot add sources once it is enabled. On first reading, I was sure I understood it as the opposite - the error is raised when adding sources and the service is not enabled.
Perhaps we should call it running, or started? Alternatively, you could add a comment to explain, since normally things are not usable while disabled, while here it's the opposite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
operator IntType() const; | ||
|
||
private: | ||
std::atomic<IntType> val_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the overhead of using std:atomic here with SimpleIntegerDiagnosticData? The majority of cases the diagnostic data doesn't need to be thread safe, only a few cases need it, so the non-atomic version should be the more efficient case ideally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SimpleIntegerDiagnosticData
uses a dummy NoLockingPolicy
, so there shouldn't be any overhead. The class in question is a specialization of IntegerDiagnosticData
for AtomicLockingPolicy
, i.e. it's always up to a developer to decide if a particular diagnostic data needs to be updated atomically.
|
||
template<typename LockingPolicyT> | ||
inline particle::AbstractIntegerDiagnosticData::IntType particle::IntegerDiagnosticData<LockingPolicyT>::operator++() { | ||
LockingPolicyT::lock(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RAII opportunity here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
…o provide the data for this.
…pt the Core" This reverts commit ca4a396.
Problem
This PR implements a simple service allowing the system and applications to register diagnostic data sources.
Steps to Test
Run unit tests.
Example App
References
Completeness