OLD | NEW |
---|---|
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 17 matching lines...) Expand all Loading... | |
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(int record_size_in_bytes, |
37 int desired_chunk_size_in_bytes, | 37 int desired_chunk_size_in_bytes, |
38 int buffer_size_in_chunks) | 38 int buffer_size_in_chunks, |
39 int producer_consumer_distance) | |
loislo
2013/02/21 12:42:39
I'd pass a boolean or enum flag instead of a magic
yurys
2013/02/21 12:45:48
Done.
| |
39 : record_size_(record_size_in_bytes / sizeof(Cell)), | 40 : record_size_(record_size_in_bytes / sizeof(Cell)), |
40 chunk_size_in_bytes_(desired_chunk_size_in_bytes / record_size_in_bytes * | 41 chunk_size_in_bytes_(desired_chunk_size_in_bytes / record_size_in_bytes * |
41 record_size_in_bytes), | 42 record_size_in_bytes), |
42 chunk_size_(chunk_size_in_bytes_ / sizeof(Cell)), | 43 chunk_size_(chunk_size_in_bytes_ / sizeof(Cell)), |
43 buffer_size_(chunk_size_ * buffer_size_in_chunks), | 44 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)) { | 45 buffer_(NewArray<Cell>(buffer_size_ + 1)) { |
49 ASSERT(buffer_size_in_chunks > 2); | 46 ASSERT(buffer_size_in_chunks > 2); |
50 // Clean up the whole buffer to avoid encountering a random kEnd | 47 // Clean up the whole buffer to avoid encountering a random kEnd |
51 // while enqueuing. | 48 // while enqueuing. |
52 for (int i = 0; i < buffer_size_; ++i) { | 49 for (int i = 0; i < buffer_size_; ++i) { |
53 buffer_[i] = kClear; | 50 buffer_[i] = kClear; |
54 } | 51 } |
55 buffer_[buffer_size_] = kEnd; | 52 buffer_[buffer_size_] = kEnd; |
56 | 53 |
57 // Layout producer and consumer position pointers each on their own | 54 // Layout producer and consumer position pointers each on their own |
58 // cache lines to avoid cache lines thrashing due to simultaneous | 55 // cache lines to avoid cache lines thrashing due to simultaneous |
59 // updates of positions by different processor cores. | 56 // updates of positions by different processor cores. |
60 const int positions_size = | 57 const int positions_size = |
61 RoundUp(1, kProcessorCacheLineSize) + | 58 RoundUp(1, kProcessorCacheLineSize) + |
62 RoundUp(static_cast<int>(sizeof(ProducerPosition)), | 59 RoundUp(static_cast<int>(sizeof(ProducerPosition)), |
63 kProcessorCacheLineSize) + | 60 kProcessorCacheLineSize) + |
64 RoundUp(static_cast<int>(sizeof(ConsumerPosition)), | 61 RoundUp(static_cast<int>(sizeof(ConsumerPosition)), |
65 kProcessorCacheLineSize); | 62 kProcessorCacheLineSize); |
66 positions_ = NewArray<byte>(positions_size); | 63 positions_ = NewArray<byte>(positions_size); |
67 | 64 |
68 producer_pos_ = reinterpret_cast<ProducerPosition*>( | 65 producer_pos_ = reinterpret_cast<ProducerPosition*>( |
69 RoundUp(positions_, kProcessorCacheLineSize)); | 66 RoundUp(positions_, kProcessorCacheLineSize)); |
70 producer_pos_->enqueue_pos = buffer_; | 67 producer_pos_->enqueue_pos = buffer_; |
71 | 68 |
72 consumer_pos_ = reinterpret_cast<ConsumerPosition*>( | 69 consumer_pos_ = reinterpret_cast<ConsumerPosition*>( |
73 reinterpret_cast<byte*>(producer_pos_) + kProcessorCacheLineSize); | 70 reinterpret_cast<byte*>(producer_pos_) + kProcessorCacheLineSize); |
74 ASSERT(reinterpret_cast<byte*>(consumer_pos_ + 1) <= | 71 ASSERT(reinterpret_cast<byte*>(consumer_pos_ + 1) <= |
75 positions_ + positions_size); | 72 positions_ + positions_size); |
76 consumer_pos_->dequeue_chunk_pos = buffer_; | 73 consumer_pos_->dequeue_chunk_pos = buffer_; |
77 consumer_pos_->dequeue_chunk_poll_pos = buffer_ + producer_consumer_distance_; | 74 // The distance ensures that producer and consumer never step on |
75 // each other's chunks and helps eviction of produced data from | |
76 // the CPU cache (having that chunk size is bigger than the cache.) | |
77 producer_consumer_distance *= chunk_size_; | |
78 consumer_pos_->dequeue_chunk_poll_pos = buffer_ + producer_consumer_distance; | |
78 consumer_pos_->dequeue_pos = NULL; | 79 consumer_pos_->dequeue_pos = NULL; |
79 } | 80 } |
80 | 81 |
81 | 82 |
82 SamplingCircularQueue::~SamplingCircularQueue() { | 83 SamplingCircularQueue::~SamplingCircularQueue() { |
83 DeleteArray(positions_); | 84 DeleteArray(positions_); |
84 DeleteArray(buffer_); | 85 DeleteArray(buffer_); |
85 } | 86 } |
86 | 87 |
87 | 88 |
(...skipping 25 matching lines...) Expand all Loading... | |
113 } | 114 } |
114 | 115 |
115 | 116 |
116 void SamplingCircularQueue::FlushResidualRecords() { | 117 void SamplingCircularQueue::FlushResidualRecords() { |
117 // Eliminate producer / consumer distance. | 118 // Eliminate producer / consumer distance. |
118 consumer_pos_->dequeue_chunk_poll_pos = consumer_pos_->dequeue_chunk_pos; | 119 consumer_pos_->dequeue_chunk_poll_pos = consumer_pos_->dequeue_chunk_pos; |
119 } | 120 } |
120 | 121 |
121 | 122 |
122 } } // namespace v8::internal | 123 } } // namespace v8::internal |
OLD | NEW |