diff options
author | Patrick Williams <iawillia@us.ibm.com> | 2011-03-31 16:34:01 -0500 |
---|---|---|
committer | Patrick Williams <iawillia@us.ibm.com> | 2011-03-31 16:34:01 -0500 |
commit | bc6668cd04209d34c04b84139fdfb353166e3335 (patch) | |
tree | 827e0a8818f11268e113c5b4aee63f9b1f3e3f4d /src/usr/trace/TraceBuffer.C | |
parent | ec8abe32d3eccc9ef46341a045097b5d4abde886 (diff) | |
download | blackbird-hostboot-bc6668cd04209d34c04b84139fdfb353166e3335.tar.gz blackbird-hostboot-bc6668cd04209d34c04b84139fdfb353166e3335.zip |
Initial code for trace api.
Diffstat (limited to 'src/usr/trace/TraceBuffer.C')
-rw-r--r-- | src/usr/trace/TraceBuffer.C | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/usr/trace/TraceBuffer.C b/src/usr/trace/TraceBuffer.C new file mode 100644 index 000000000..c10afcfa3 --- /dev/null +++ b/src/usr/trace/TraceBuffer.C @@ -0,0 +1,53 @@ +#include <limits.h> +#include "TraceBuffer.H" + +TracePage* TracePage::setNext(TracePage* new_next) +{ + return __sync_val_compare_and_swap(&this->next, NULL, new_next); +} + +traceEntry* TracePage::claimEntry(size_t size) +{ + size_t position = __sync_fetch_and_add(&this->size, size); + if (position > (PAGE_SIZE - sizeof(TracePage))) + { + return NULL; + } + else + { + return (traceEntry*)&((uint8_t*)this)[sizeof(TracePage) + position]; + } +} + +traceEntry* TraceBuffer::claimEntry(size_t size) +{ + traceEntry* result = NULL; + TracePage* page = last; + + while (result == NULL) + { + result = page->claimEntry(size); + + if (NULL == result) + { + if (NULL != page->getNext()) + { + __sync_bool_compare_and_swap(&this->last, + page, page->getNext()); + page = page->getNext(); + } + else + { + TracePage* new_page = new (malloc(PAGE_SIZE)) TracePage(); + TracePage* prev = page; + + while(prev != NULL) + { + prev = prev->setNext(new_page); + } + } + } + } + + return result; +} |