Lines Matching refs:the

5 variables associated with the *currently* executing processor. This is
6 done through the use of segment registers (or a dedicated register where
7 the cpu permanently stored the beginning of the per cpu area for a
10 this_cpu operations add a per cpu variable offset to the processor
11 specific per cpu base and encode that operation in the instruction
12 operating on the per cpu variable.
14 This means that there are no atomicity issues between the calculation of
15 the offset and the operation on the data. Therefore it is not
16 necessary to disable preemption or interrupts to ensure that the
17 processor is not changed between the calculation of the address and
18 the operation on the data.
22 without the typical synchronization overhead, but still provide some
24 RMW (Read Modify Write) instructions like inc/dec/cmpxchg without the
25 lock prefix and the associated latency penalty.
27 Access to the variable without the lock prefix is not synchronized but
29 data specific to the currently executing processor. Only the current
31 concurrency issues with other processors in the system.
37 The main use of the this_cpu operations has been to optimize counter
64 On x86 the fs: or the gs: segment registers contain the base of the
65 per cpu area. It is then possible to simply use the segment override
66 to relocate a per cpu relative address to the proper per cpu area for
67 the processor. So the relocation to the per cpu base is encoded in the
81 instead of a sequence of calculation of the address and then a fetch
82 from that address which occurs with the per cpu operations. Before
84 prevent the kernel from moving the thread to a different processor
85 while the calculation is performed.
87 Consider the following this_cpu operation:
91 The above results in the following single instruction (no lock prefix!)
95 instead of the following operations required if there is no segment
107 reserved for a specific processor. Without disabling preemption in the
108 surrounding code this_cpu_inc() will only guarantee that one of the
110 guarantee that the OS will not move the process directly before or
111 after the this_cpu instruction is executed. In general this means that
112 the value of the individual counters for each processor are
113 meaningless. The sum of all the per cpu counters is the only value
118 the same code paths. Since each processor has its own per cpu
120 has to be paid for this optimization is the need to add up the per cpu
121 counters when the value of a counter is needed.
129 Takes the offset of a per cpu variable (&x !) and returns the address
130 of the per cpu variable that belongs to the currently executing
131 processor. this_cpu_ptr avoids multiple steps that the common
133 available. Instead, the offset of the local per cpu area is simply
134 added to the per cpu offset.
140 no longer point to per cpu data of the current processor.
146 Per cpu variables have *offsets* to the beginning of the per cpu
147 area. They do not have addresses although they look like that in the
152 Therefore the use of x or &x outside of the context of per cpu
158 In the context of per cpu operations the above implies that x is a per
163 &x and hence p is the *offset* of a per cpu variable. this_cpu_ptr()
164 takes the offset of a per cpu variable which makes this look a bit
196 The calculation of the pointer may require the use of this_cpu_ptr()
212 these per cpu local operations. In that case the operation must be
213 replaced by code that disables interrupts, then does the operations
215 so is expensive. If there are other reasons why the scheduler cannot
216 change the processor we are executing on then there is no reason to
217 disable interrupts. For that purpose the following __this_cpu operations
222 and the scheduler cannot preempt, then they are safe. If any interrupts
223 still occur while an operation is in progress and if the interrupt too
224 modifies the variable, then RMW actions can not be guaranteed to be
246 address relocation and a Read-Modify-Write operation in the same
253 The first operation takes the offset and forms an address and then
254 adds the offset of the n field. This may result in two add
255 instructions emitted by the compiler.
257 The second one first adds the two offsets and then does the
258 relocation. IMHO the second form looks cleaner and has an easier time
259 with (). The second form also is consistent with the way
267 If you use the variables as intended, this_cpu_ops() are guaranteed to
279 the remote CPU and perform the update to its per cpu area.
281 To access per-cpu data structure remotely, typically the per_cpu_ptr()
292 You can also do the following to convert the datap offset to an address
299 Remote access are typically only for reading the status of another cpus
300 per cpu data. Write accesses can cause unique problems due to the
304 the following scenario that occurs because two per cpu variables
305 share a cache-line but the relaxed synchronization is applied to
306 only one process updating the cache-line.
308 Consider the following example
318 There is some concern about what would happen if the field 'a' is updated
319 remotely from one processor and the local processor would use this_cpu ops
321 data within the same cache line are avoided. Also costly synchronization
323 of a remote write to the per cpu area of another processor.
325 Even in cases where the remote writes are rare, please bear in
326 mind that a remote write will evict the cache line from the processor
327 that most likely will access it. If the processor wakes up and finds a
329 the wake up times will be affected.