From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60878) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XEr4a-0002Gd-JV for qemu-devel@nongnu.org; Tue, 05 Aug 2014 22:35:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XEr4O-0001g4-TA for qemu-devel@nongnu.org; Tue, 05 Aug 2014 22:35:28 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:49933) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XEr4O-0001dc-Lz for qemu-devel@nongnu.org; Tue, 05 Aug 2014 22:35:16 -0400 Received: from mail-vc0-f180.google.com ([209.85.220.180]) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1XEr4N-0005lL-9W for qemu-devel@nongnu.org; Wed, 06 Aug 2014 02:35:15 +0000 Received: by mail-vc0-f180.google.com with SMTP id ij19so3063688vcb.39 for ; Tue, 05 Aug 2014 19:35:14 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <53E0C645.5050106@redhat.com> References: <1407209598-2572-1-git-send-email-ming.lei@canonical.com> <1407209598-2572-2-git-send-email-ming.lei@canonical.com> <53E0C645.5050106@redhat.com> Date: Wed, 6 Aug 2014 10:35:14 +0800 Message-ID: From: Ming Lei Content-Type: text/plain; charset=UTF-8 Subject: Re: [Qemu-devel] [PATCH v1 01/17] qemu/obj_pool.h: introduce object allocation pool List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: Kevin Wolf , Peter Maydell , Fam Zheng , "Michael S. Tsirkin" , qemu-devel , Stefan Hajnoczi , Paolo Bonzini On Tue, Aug 5, 2014 at 7:55 PM, Eric Blake wrote: > On 08/04/2014 09:33 PM, Ming Lei wrote: >> This patch introduces object allocation pool for speeding up >> object allocation in fast path. >> >> Signed-off-by: Ming Lei >> --- >> include/qemu/obj_pool.h | 64 +++++++++++++++++++++++++++++++++++++++++++++++ >> 1 file changed, 64 insertions(+) >> create mode 100644 include/qemu/obj_pool.h >> >> diff --git a/include/qemu/obj_pool.h b/include/qemu/obj_pool.h >> new file mode 100644 >> index 0000000..94b5f49 >> --- /dev/null >> +++ b/include/qemu/obj_pool.h >> @@ -0,0 +1,64 @@ >> +#ifndef QEMU_OBJ_POOL_HEAD >> +#define QEMU_OBJ_POOL_HEAD > > Missing copyright boilerplate. According to LICENSE, that makes this > file GPLv2+, but I'd much rather you make it explicit. > >> + >> +typedef struct { >> + unsigned int size; >> + unsigned int cnt; > > size_t feels better for sizes. int may be okay in this case, but > definitely consider if size_t is appropriate. Sounds good. > >> + >> + void **free_obj; >> + int free_idx; >> + >> + char *objs; >> +} ObjPool; >> + >> +static inline void obj_pool_init(ObjPool *op, void *objs_buf, void **free_objs, >> + unsigned int obj_size, unsigned cnt) >> +{ >> + int i; >> + >> + op->objs = (char *)objs_buf; > > Why the cast? This is C, not C++. Right, the cast isn't needed. > >> + op->free_obj = free_objs; >> + op->size = obj_size; >> + op->cnt = cnt; >> + >> + for (i = 0; i < op->cnt; i++) { >> + op->free_obj[i] = (void *)&op->objs[i * op->size]; > > Again, why the cast? Right too. > > >> +static inline bool obj_pool_has_obj(ObjPool *op, void *obj) >> +{ >> + return op && (unsigned long)obj >= (unsigned long)&op->objs[0] && >> + (unsigned long)obj <= >> + (unsigned long)&op->objs[(op->cnt - 1) * op->size]; > > uintptr_t, not unsigned long. You are asking for problems on 64-bit > mingw, where unsigned long is 32 bits but uintptr_t is 64 bits. Good point, it is the 1st time for me to know the mingw long magic. Thanks,