Skip to content
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

A sample application to demonstrate use of kernel event logger feature. #4552

Merged
merged 2 commits into from
Nov 3, 2017

Conversation

SavinayDharmappa
Copy link
Contributor

@SavinayDharmappa SavinayDharmappa commented Oct 25, 2017

fixes #3412

Copy link
Contributor

@dbkinder dbkinder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested edits

@@ -0,0 +1,40 @@
.. _kerneleventlogger_sample:

Kerneleventlogger Sample
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about:

 Kernel Event Logger Sample
 ##########################

Note the #### underline must be at least as long as the title above it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


A simple application that demonstrates use of kernel event
logger feature.Two threads (A and B) of same priority are
created and another thread with less priority (i.e event_
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Words that end with an underscore are meaningful to the doc gen process, so break the line before event_ so the line doesn't end with an underscore. Also some clarity edits:

 created and a third thread with lower priority (i.e.,
 event_logger_thread) is also created, which reads
 the events from 

********

A simple application that demonstrates use of kernel event
logger feature.Two threads (A and B) of same priority are
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a space after the period ending a sentence

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k

********

A simple application that demonstrates use of kernel event
logger feature.Two threads (A and B) of same priority are
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and change to "of the same priority"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k

logger feature.Two threads (A and B) of same priority are
created and another thread with less priority (i.e event_
logger_thread)is also created which reads the events from
kernel event loggerbuffer and prints on to the console.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to:

 kernel event logger's buffer

to match what you've written below, and change "prints on to" to just "prints to"

created and another thread with less priority (i.e event_
logger_thread)is also created which reads the events from
kernel event loggerbuffer and prints on to the console.
When thread 'A' gets schecduled it will sleep for 1 second.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scheduled

kernel event loggerbuffer and prints on to the console.
When thread 'A' gets schecduled it will sleep for 1 second.
Similarly when thread 'B' gets scheduled it will sleep for
0.5 seconds. When both A and B are sleeping event logger
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to:

... are sleeping, the event logger

When thread 'A' gets schecduled it will sleep for 1 second.
Similarly when thread 'B' gets scheduled it will sleep for
0.5 seconds. When both A and B are sleeping event logger
thread gets scheduled and retrieve the events captured
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

retrieves

Similarly when thread 'B' gets scheduled it will sleep for
0.5 seconds. When both A and B are sleeping event logger
thread gets scheduled and retrieve the events captured
from kernel event loggers buffer and prints it on the console.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logger's

@@ -0,0 +1,40 @@
.. _kerneleventlogger_sample:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the first document in the logging area, so you'll need to also add a file samples/subsys/logging/logging.rst that looks like samples/subsys/console/console.rst (copy that one and edit the title). This will remove the "not included in a toc-tree" warning.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

obj-y += main.o

ccflags-y += -I${ZEPHYR_BASE}/ext/debug/segger/rtt
ccflags-y += -I${ZEPHYR_BASE}/ext/debug/segger/systemview
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you do not need those


timestamp = event_data[0];

switch (event_id) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a default to the switch

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

case KERNEL_EVENT_LOGGER_SLEEP_EVENT_ID:
break;
case KERNEL_EVENT_LOGGER_THREAD_EVENT_ID:
printk("thread = %x, is moved to = %s ,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reformat this message, this should fit in 2 lines and would be more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok.

static u32_t timestamp;
char thread_event_type[][12] = {"REDAY_Q", "PEND_STATE", "EXIT_STATE"};

static void event_logger_thread(void)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not make this the main thread?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thread which reads event from the kernel event logger should be of least priority, because this thread should not affect application related threads. As main thread is set with priority zero, it should not be used for reading events from event loggers

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can change the main thread priority using CONFIG_MAIN_THREAD_PRIORITY

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok .

@SavinayDharmappa SavinayDharmappa force-pushed the issue_3412 branch 5 times, most recently from db20ecf to f8e847a Compare October 30, 2017 16:04
Copy link
Contributor

@dbkinder dbkinder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

almost done...


A simple application that demonstrates use of kernel event
logger feature. Two threads (A and B) of the same priority
are created and main thread is configured to have low priority ,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete space before the comma

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

which reads the events from kernel event logger's buffer and
prints to the console. When thread 'A' gets scheduled it will
sleep for 1 second. Similarly when thread 'B' gets scheduled
it will sleep for 0.5 seconds. When both A and B are sleeping ,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete space before the comma

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

A CPU fault occurs when sys_k_event_logger_get_wait()
api invoked with config KERNEL_EVENT_LOGGER_THREAD
enabled.

sys_k_event_logger_get_wait() supposed to pend  on a
semaphore when all the events from kernel event logger
are read.But when sys_k_event_logger_get_wait() inovked
with config KERNEL_EVENT_LOGGER_THREAD(i.e captures thread
events) subsquent call inside this function will write to
kernel event log buffer to capture pend event.This will
release the semaphore on which sys_k_event_logger_get_wait()
was pending hence thread gets unpend before swap gets called.

Which in other words a thread which is invoking
sys_k_event_logger_get_wait()(i. e sem_count = 0) get pends
and unpends in single function flow when KERNEL_EVENT_LOGGER_THREAD
enabled.

This would cause overlapping of the stack address where
return address of "_pend_current_thread" stored with esp of
callee saved(i. e thread->callee_saved.esp). Thus return adrress
of "_pend_current_thread" would be overwitten with zero. Which
in turn causes CPU fault.

The thread invoking sys_k_event_logger_get_wait() supposed
to only read the events of the threads which logged to kernel event
logger buffer. But it should not write to kernel event logger
buffer. Otherwise it would cause the race condition explained above.

Signed-off-by: Savinay Dharmappa <[email protected]>
patch adds a sample application to demonstrate use of kernel event
logger feature.

Signed-off-by: Savinay Dharmappa <[email protected]>
@nashif nashif merged commit 4cec152 into zephyrproject-rtos:master Nov 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide a sample application for kernel_event_logger
3 participants