Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: src/circular-queue.cc

Issue 12321046: Send SIGPROF signals on the profiler event processor thread (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Fixed typo: Profler->Profiler Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/circular-queue.h ('k') | src/cpu-profiler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 15 matching lines...) Expand all
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include "v8.h" 28 #include "v8.h"
29 29
30 #include "circular-queue-inl.h" 30 #include "circular-queue-inl.h"
31 31
32 namespace v8 { 32 namespace v8 {
33 namespace internal { 33 namespace internal {
34 34
35 35
36 SamplingCircularQueue::SamplingCircularQueue(int record_size_in_bytes, 36 SamplingCircularQueue::SamplingCircularQueue(
37 int desired_chunk_size_in_bytes, 37 int record_size_in_bytes,
38 int buffer_size_in_chunks) 38 int desired_chunk_size_in_bytes,
39 int buffer_size_in_chunks,
40 bool keep_producer_consumer_distance)
39 : record_size_(record_size_in_bytes / sizeof(Cell)), 41 : record_size_(record_size_in_bytes / sizeof(Cell)),
40 chunk_size_in_bytes_(desired_chunk_size_in_bytes / record_size_in_bytes * 42 chunk_size_in_bytes_(desired_chunk_size_in_bytes / record_size_in_bytes *
41 record_size_in_bytes), 43 record_size_in_bytes),
42 chunk_size_(chunk_size_in_bytes_ / sizeof(Cell)), 44 chunk_size_(chunk_size_in_bytes_ / sizeof(Cell)),
43 buffer_size_(chunk_size_ * buffer_size_in_chunks), 45 buffer_size_(chunk_size_ * buffer_size_in_chunks),
44 // The distance ensures that producer and consumer never step on
45 // each other's chunks and helps eviction of produced data from
46 // the CPU cache (having that chunk size is bigger than the cache.)
47 producer_consumer_distance_(2 * chunk_size_),
48 buffer_(NewArray<Cell>(buffer_size_ + 1)) { 46 buffer_(NewArray<Cell>(buffer_size_ + 1)) {
49 ASSERT(buffer_size_in_chunks > 2); 47 ASSERT(buffer_size_in_chunks > 2);
50 // Clean up the whole buffer to avoid encountering a random kEnd 48 // Clean up the whole buffer to avoid encountering a random kEnd
51 // while enqueuing. 49 // while enqueuing.
52 for (int i = 0; i < buffer_size_; ++i) { 50 for (int i = 0; i < buffer_size_; ++i) {
53 buffer_[i] = kClear; 51 buffer_[i] = kClear;
54 } 52 }
55 buffer_[buffer_size_] = kEnd; 53 buffer_[buffer_size_] = kEnd;
56 54
57 // Layout producer and consumer position pointers each on their own 55 // Layout producer and consumer position pointers each on their own
58 // cache lines to avoid cache lines thrashing due to simultaneous 56 // cache lines to avoid cache lines thrashing due to simultaneous
59 // updates of positions by different processor cores. 57 // updates of positions by different processor cores.
60 const int positions_size = 58 const int positions_size =
61 RoundUp(1, kProcessorCacheLineSize) + 59 RoundUp(1, kProcessorCacheLineSize) +
62 RoundUp(static_cast<int>(sizeof(ProducerPosition)), 60 RoundUp(static_cast<int>(sizeof(ProducerPosition)),
63 kProcessorCacheLineSize) + 61 kProcessorCacheLineSize) +
64 RoundUp(static_cast<int>(sizeof(ConsumerPosition)), 62 RoundUp(static_cast<int>(sizeof(ConsumerPosition)),
65 kProcessorCacheLineSize); 63 kProcessorCacheLineSize);
66 positions_ = NewArray<byte>(positions_size); 64 positions_ = NewArray<byte>(positions_size);
67 65
68 producer_pos_ = reinterpret_cast<ProducerPosition*>( 66 producer_pos_ = reinterpret_cast<ProducerPosition*>(
69 RoundUp(positions_, kProcessorCacheLineSize)); 67 RoundUp(positions_, kProcessorCacheLineSize));
70 producer_pos_->enqueue_pos = buffer_; 68 producer_pos_->enqueue_pos = buffer_;
71 69
72 consumer_pos_ = reinterpret_cast<ConsumerPosition*>( 70 consumer_pos_ = reinterpret_cast<ConsumerPosition*>(
73 reinterpret_cast<byte*>(producer_pos_) + kProcessorCacheLineSize); 71 reinterpret_cast<byte*>(producer_pos_) + kProcessorCacheLineSize);
74 ASSERT(reinterpret_cast<byte*>(consumer_pos_ + 1) <= 72 ASSERT(reinterpret_cast<byte*>(consumer_pos_ + 1) <=
75 positions_ + positions_size); 73 positions_ + positions_size);
76 consumer_pos_->dequeue_chunk_pos = buffer_; 74 consumer_pos_->dequeue_chunk_pos = buffer_;
77 consumer_pos_->dequeue_chunk_poll_pos = buffer_ + producer_consumer_distance_; 75 consumer_pos_->dequeue_chunk_poll_pos = buffer_;
76 // The distance ensures that producer and consumer never step on
77 // each other's chunks and helps eviction of produced data from
78 // the CPU cache (having that chunk size is bigger than the cache.)
79 if (keep_producer_consumer_distance) {
80 consumer_pos_->dequeue_chunk_poll_pos += 2 * chunk_size_;
81 }
78 consumer_pos_->dequeue_pos = NULL; 82 consumer_pos_->dequeue_pos = NULL;
79 } 83 }
80 84
81 85
82 SamplingCircularQueue::~SamplingCircularQueue() { 86 SamplingCircularQueue::~SamplingCircularQueue() {
83 DeleteArray(positions_); 87 DeleteArray(positions_);
84 DeleteArray(buffer_); 88 DeleteArray(buffer_);
85 } 89 }
86 90
87 91
(...skipping 25 matching lines...) Expand all
113 } 117 }
114 118
115 119
116 void SamplingCircularQueue::FlushResidualRecords() { 120 void SamplingCircularQueue::FlushResidualRecords() {
117 // Eliminate producer / consumer distance. 121 // Eliminate producer / consumer distance.
118 consumer_pos_->dequeue_chunk_poll_pos = consumer_pos_->dequeue_chunk_pos; 122 consumer_pos_->dequeue_chunk_poll_pos = consumer_pos_->dequeue_chunk_pos;
119 } 123 }
120 124
121 125
122 } } // namespace v8::internal 126 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/circular-queue.h ('k') | src/cpu-profiler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698