Hi,
thanks for sharing this early.
On Sat, Mar 27, 2010 at 08:53, wrote:
> Modified: branches/dyncpusets/src/cpuset.c
> ==
> --- branches/dyncpusets/src/cpuset.c (original)
> +++ branches/dyncpusets/src/cpuset.c 2010-03-27 03:53:47 EDT (Sat, 27 Mar
> 2010)
> @@ -50,10 +63,18 @@
> struct hwloc_cpuset_s * hwloc_cpuset_alloc(void)
> {
> struct hwloc_cpuset_s * set;
> - set = calloc(sizeof(*set), 1);
> + set = malloc(sizeof(struct hwloc_cpuset_s));
> if (!set)
> return NULL;
>
> + set->ulongs_count = 1;
> + set->ulongs = calloc(sizeof(unsigned long), set->ulongs_count);
> + if (!set->ulongs) {
> + free(set->ulongs);
That should be free(set).
> + return NULL;
> + }
> +
> + set->infinite = 0;
> #ifdef HWLOC_DEBUG
> set->magic = HWLOC_CPUSET_MAGIC;
> #endif
> @@ -70,29 +91,78 @@
> set->magic = 0;
> #endif
>
> + free(set->ulongs);
> free(set);
> }
>
> +/* realloc until it contains at least needed_count ulongs */
> +static void
> +hwloc_cpuset_realloc_by_ulongs(struct hwloc_cpuset_s * set, unsigned
> needed_count)
> +{
> + unsigned ulongs_count = set->ulongs_count;
> + unsigned i;
> +
> + HWLOC__CPUSET_CHECK(set);
> +
> + if (needed_count <= ulongs_count)
> + return;
> +
> + while (ulongs_count < needed_count)
> + ulongs_count *= 2;
You may have notices, that I don't like exponential realloc schemes.
On the other hand, I know that you plan to use a sparse implementation
in the future, so this is probably only an intermediate step. Anyway,
in this case, because one ulong should suffice for the common case, a
linear scheme with an increment of 1 would be crazy, I would use an
exponential scheme until some limit and from that on a linear scheme
(with that limit as the increment). The cache line size would be such
limit and a good one I think.
Regards,
Bert