From patchwork Fri Apr 29 15:15:02 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 741281 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p3TFFq8R002233 for ; Fri, 29 Apr 2011 15:15:53 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755130Ab1D2PPs (ORCPT ); Fri, 29 Apr 2011 11:15:48 -0400 Received: from mail-ww0-f42.google.com ([74.125.82.42]:53925 "EHLO mail-ww0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754348Ab1D2PPr (ORCPT ); Fri, 29 Apr 2011 11:15:47 -0400 Received: by wwk4 with SMTP id 4so597247wwk.1 for ; Fri, 29 Apr 2011 08:15:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer; bh=VJMlMie2IYV9AZwd8NrDG2JXBD53G49JO39s0OFuLMM=; b=RpjETdN44EB5AooqpNl1qq4CAiojGHvVGRuHBSMWZ4lSMEDFl4uI5AtBT7lOtYOVk8 REc9ugD2x5H69YEMVzS0bOl+rk0MrVuJC3VwhneWXgGBFvKbZxtfrrDe6OeNufy2QHVW x+MEnJMjCfQEaFvYitzK8vfedJFJ9FGmeiiX8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=E9oppunoL/hCxFQuUP3ZUxNd7/RsuTnqmJdyylPTAm+TPs0pM8cbGnI2qHMkcfM+yj Swmt/sV+vf0kpPl+GgdB91fsd/tEpzDalhmca4hQFZg3/3YZd0k0OY+18jK8+J/kZCHt G9RJg2gkNfhANRqKUEeuVn7tPkWp0IUOyvxFo= Received: by 10.216.246.5 with SMTP id p5mr753054wer.64.1304090146261; Fri, 29 Apr 2011 08:15:46 -0700 (PDT) Received: from localhost.localdomain (bzq-79-179-208-226.red.bezeqint.net [79.179.208.226]) by mx.google.com with ESMTPS id l24sm1765951wbc.30.2011.04.29.08.15.44 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 29 Apr 2011 08:15:45 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: mingo@elte.hu, asias.hejun@gmail.com, gorcunov@gmail.com, prasadjoshi124@gmail.com, kvm@vger.kernel.org, Sasha Levin Subject: [PATCH] kvm tools: Modify thread pool API Date: Fri, 29 Apr 2011 18:15:02 +0300 Message-Id: <1304090102-3416-1-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.5.rc3 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Fri, 29 Apr 2011 15:15:53 +0000 (UTC) Modify API function names and type names. Signed-off-by: Sasha Levin --- tools/kvm/include/kvm/threadpool.h | 4 +- tools/kvm/threadpool.c | 42 ++++++++++++++++++------------------ tools/kvm/virtio-blk.c | 4 +- tools/kvm/virtio-console.c | 8 +++--- tools/kvm/virtio-net.c | 6 ++-- 5 files changed, 32 insertions(+), 32 deletions(-) diff --git a/tools/kvm/include/kvm/threadpool.h b/tools/kvm/include/kvm/threadpool.h index 25b5eb8..4716411 100644 --- a/tools/kvm/include/kvm/threadpool.h +++ b/tools/kvm/include/kvm/threadpool.h @@ -9,8 +9,8 @@ typedef void (*kvm_thread_callback_fn_t)(struct kvm *kvm, void *data); int thread_pool__init(unsigned long thread_count); -void *thread_pool__add_jobtype(struct kvm *kvm, kvm_thread_callback_fn_t callback, void *data); +void *thread_pool__add_job(struct kvm *kvm, kvm_thread_callback_fn_t callback, void *data); -void thread_pool__signal_work(void *job); +void thread_pool__do_job(void *job); #endif diff --git a/tools/kvm/threadpool.c b/tools/kvm/threadpool.c index c584ec7..25d9aad 100644 --- a/tools/kvm/threadpool.c +++ b/tools/kvm/threadpool.c @@ -6,7 +6,7 @@ #include #include -struct thread_pool__job_info { +struct thread_pool__job { kvm_thread_callback_fn_t callback; struct kvm *kvm; void *data; @@ -26,42 +26,42 @@ static LIST_HEAD(head); static pthread_t *threads; static long threadcount; -static struct thread_pool__job_info *thread_pool__job_info_pop(void) +static struct thread_pool__job *thread_pool__job_pop(void) { - struct thread_pool__job_info *job; + struct thread_pool__job *job; if (list_empty(&head)) return NULL; - job = list_first_entry(&head, struct thread_pool__job_info, queue); + job = list_first_entry(&head, struct thread_pool__job, queue); list_del(&job->queue); return job; } -static void thread_pool__job_info_push(struct thread_pool__job_info *job) +static void thread_pool__job_push(struct thread_pool__job *job) { list_add_tail(&job->queue, &head); } -static struct thread_pool__job_info *thread_pool__job_info_pop_locked(void) +static struct thread_pool__job *thread_pool__job_pop_locked(void) { - struct thread_pool__job_info *job; + struct thread_pool__job *job; mutex_lock(&job_mutex); - job = thread_pool__job_info_pop(); + job = thread_pool__job_pop(); mutex_unlock(&job_mutex); return job; } -static void thread_pool__job_info_push_locked(struct thread_pool__job_info *job) +static void thread_pool__job_push_locked(struct thread_pool__job *job) { mutex_lock(&job_mutex); - thread_pool__job_info_push(job); + thread_pool__job_push(job); mutex_unlock(&job_mutex); } -static void thread_pool__handle_job(struct thread_pool__job_info *job) +static void thread_pool__handle_job(struct thread_pool__job *job) { while (job) { job->callback(job->kvm, job->data); @@ -70,11 +70,11 @@ static void thread_pool__handle_job(struct thread_pool__job_info *job) if (--job->signalcount > 0) /* If the job was signaled again while we were working */ - thread_pool__job_info_push_locked(job); + thread_pool__job_push_locked(job); mutex_unlock(&job->mutex); - job = thread_pool__job_info_pop_locked(); + job = thread_pool__job_pop_locked(); } } @@ -88,11 +88,11 @@ static void *thread_pool__threadfunc(void *param) pthread_cleanup_push(thread_pool__threadfunc_cleanup, NULL); for (;;) { - struct thread_pool__job_info *curjob; + struct thread_pool__job *curjob; mutex_lock(&job_mutex); pthread_cond_wait(&job_cond, &job_mutex); - curjob = thread_pool__job_info_pop(); + curjob = thread_pool__job_pop(); mutex_unlock(&job_mutex); if (curjob) @@ -139,12 +139,12 @@ int thread_pool__init(unsigned long thread_count) return i; } -void *thread_pool__add_jobtype(struct kvm *kvm, +void *thread_pool__add_job(struct kvm *kvm, kvm_thread_callback_fn_t callback, void *data) { - struct thread_pool__job_info *job = calloc(1, sizeof(*job)); + struct thread_pool__job *job = calloc(1, sizeof(*job)); - *job = (struct thread_pool__job_info) { + *job = (struct thread_pool__job) { .kvm = kvm, .data = data, .callback = callback, @@ -154,16 +154,16 @@ void *thread_pool__add_jobtype(struct kvm *kvm, return job; } -void thread_pool__signal_work(void *job) +void thread_pool__do_job(void *job) { - struct thread_pool__job_info *jobinfo = job; + struct thread_pool__job *jobinfo = job; if (jobinfo == NULL) return; mutex_lock(&jobinfo->mutex); if (jobinfo->signalcount++ == 0) - thread_pool__job_info_push_locked(job); + thread_pool__job_push_locked(job); mutex_unlock(&jobinfo->mutex); pthread_cond_signal(&job_cond); diff --git a/tools/kvm/virtio-blk.c b/tools/kvm/virtio-blk.c index 3feabd0..9034abd 100644 --- a/tools/kvm/virtio-blk.c +++ b/tools/kvm/virtio-blk.c @@ -188,7 +188,7 @@ static bool virtio_blk_pci_io_out(struct kvm *self, uint16_t port, void *data, i vring_init(&queue->vring, VIRTIO_BLK_QUEUE_SIZE, p, 4096); blk_device.jobs[blk_device.queue_selector] = - thread_pool__add_jobtype(self, virtio_blk_do_io, queue); + thread_pool__add_job(self, virtio_blk_do_io, queue); break; } @@ -198,7 +198,7 @@ static bool virtio_blk_pci_io_out(struct kvm *self, uint16_t port, void *data, i case VIRTIO_PCI_QUEUE_NOTIFY: { uint16_t queue_index; queue_index = ioport__read16(data); - thread_pool__signal_work(blk_device.jobs[queue_index]); + thread_pool__do_job(blk_device.jobs[queue_index]); break; } case VIRTIO_PCI_STATUS: diff --git a/tools/kvm/virtio-console.c b/tools/kvm/virtio-console.c index e66d198..f440ded 100644 --- a/tools/kvm/virtio-console.c +++ b/tools/kvm/virtio-console.c @@ -85,7 +85,7 @@ static void virtio_console__inject_interrupt_callback(struct kvm *self, void *pa void virtio_console__inject_interrupt(struct kvm *self) { - thread_pool__signal_work(console_device.jobs[VIRTIO_CONSOLE_RX_QUEUE]); + thread_pool__do_job(console_device.jobs[VIRTIO_CONSOLE_RX_QUEUE]); } static bool virtio_console_pci_io_device_specific_in(void *data, unsigned long offset, int size, uint32_t count) @@ -190,10 +190,10 @@ static bool virtio_console_pci_io_out(struct kvm *self, uint16_t port, void *dat if (console_device.queue_selector == VIRTIO_CONSOLE_TX_QUEUE) console_device.jobs[console_device.queue_selector] = - thread_pool__add_jobtype(self, virtio_console_handle_callback, queue); + thread_pool__add_job(self, virtio_console_handle_callback, queue); else if (console_device.queue_selector == VIRTIO_CONSOLE_RX_QUEUE) console_device.jobs[console_device.queue_selector] = - thread_pool__add_jobtype(self, virtio_console__inject_interrupt_callback, queue); + thread_pool__add_job(self, virtio_console__inject_interrupt_callback, queue); break; } @@ -203,7 +203,7 @@ static bool virtio_console_pci_io_out(struct kvm *self, uint16_t port, void *dat case VIRTIO_PCI_QUEUE_NOTIFY: { uint16_t queue_index; queue_index = ioport__read16(data); - thread_pool__signal_work(console_device.jobs[queue_index]); + thread_pool__do_job(console_device.jobs[queue_index]); break; } case VIRTIO_PCI_STATUS: diff --git a/tools/kvm/virtio-net.c b/tools/kvm/virtio-net.c index 58b3de4..bbd687c 100644 --- a/tools/kvm/virtio-net.c +++ b/tools/kvm/virtio-net.c @@ -161,7 +161,7 @@ static bool virtio_net_pci_io_in(struct kvm *self, uint16_t port, void *data, in static void virtio_net_handle_callback(struct kvm *self, uint16_t queue_index) { - thread_pool__signal_work(net_device.jobs[queue_index]); + thread_pool__do_job(net_device.jobs[queue_index]); } static bool virtio_net_pci_io_out(struct kvm *self, uint16_t port, void *data, int size, uint32_t count) @@ -189,10 +189,10 @@ static bool virtio_net_pci_io_out(struct kvm *self, uint16_t port, void *data, i if (net_device.queue_selector == VIRTIO_NET_TX_QUEUE) net_device.jobs[net_device.queue_selector] = - thread_pool__add_jobtype(self, virtio_net_tx_callback, queue); + thread_pool__add_job(self, virtio_net_tx_callback, queue); else if (net_device.queue_selector == VIRTIO_NET_RX_QUEUE) net_device.jobs[net_device.queue_selector] = - thread_pool__add_jobtype(self, virtio_net_rx_callback, queue); + thread_pool__add_job(self, virtio_net_rx_callback, queue); break; }