Hi,
thanks for sharing this early.
On Sat, Mar 27, 2010 at 08:53, <bgoglin_at_[hidden]> 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
|