On 07/14/2018 12:24 AM, Dr. David Alan Gilbert wrote:
+static void *thread_run(void *opaque)
+{
+ ThreadLocal *self_data = (ThreadLocal *)opaque;
+ Threads *threads = self_data->threads;
+ void (*handler)(ThreadRequest *data) = threads->thread_request_handler;
+ ThreadRequest *request;
+ int count, ret;
+
+ for ( ; !atomic_read(&self_data->quit); ) {
+ qemu_event_reset(&self_data->ev);
+
+ count = 0;
+ while ((request = ring_get(self_data->request_ring)) ||
+ count < BUSY_WAIT_COUNT) {
+ /*
+ * wait some while before go to sleep so that the user
+ * needn't go to kernel space to wake up the consumer
+ * threads.
+ *
+ * That will waste some CPU resource indeed however it
+ * can significantly improve the case that the request
+ * will be available soon.
+ */
+ if (!request) {
+ cpu_relax();
+ count++;
+ continue;
+ }
+ count = 0;
Things like busywait counts probably need isolating somewhere;
getting those counts right is quite hard.
Okay, i will make it to be a separated function.