<commit_before>/* Copyright 2009 INRIA, Université Bordeaux 1  */

/* The cpuset API, for use in libtopology itself.  */

#ifndef LIBTOPOLOGY_CPUSET_H
#define LIBTOPOLOGY_CPUSET_H

#include <libtopology/config.h>

#include <stdint.h>
#include <string.h>
#include <strings.h>

/* large cpuset using an array of unsigned long subsets */

/* size and count of subsets within a set */
#    define TOPO_CPUSUBSET_SIZE		(8*sizeof(long))
#    define TOPO_CPUSUBSET_COUNT	((LIBTOPO_NBMAXCPUS+TOPO_CPUSUBSET_SIZE-1)/TOPO_CPUSUBSET_SIZE)
typedef struct { unsigned long s[TOPO_CPUSUBSET_COUNT]; } topo_cpuset_t;

/* extract a subset from a set using an index or a cpu */
#    define TOPO_CPUSUBSET_SUBSET(set,x)	((set).s[x])
#    define TOPO_CPUSUBSET_INDEX(cpu)		((cpu)/(TOPO_CPUSUBSET_SIZE))
#    define TOPO_CPUSUBSET_CPUSUBSET(set,cpu)	TOPO_CPUSUBSET_SUBSET(set,TOPO_CPUSUBSET_INDEX(cpu))

/* predefined subset values */
#    define TOPO_CPUSUBSET_VAL(cpu)	(1UL<<((cpu)%(TOPO_CPUSUBSET_SIZE)))
#    define TOPO_CPUSUBSET_ZERO		0UL
#    define TOPO_CPUSUBSET_FULL		~0UL

/* actual whole-cpuset values */
#    define TOPO_CPUSET_ZERO		(topo_cpuset_t){ .s[0 ... TOPO_CPUSUBSET_COUNT-1] = TOPO_CPUSUBSET_ZERO }
#    define TOPO_CPUSET_FULL		(topo_cpuset_t){ .s[0 ... TOPO_CPUSUBSET_COUNT-1] = TOPO_CPUSUBSET_FULL }
#    define TOPO_CPUSET_CPU(cpu)	({ topo_cpuset_t __set = TOPO_CPUSET_ZERO; TOPO_CPUSUBSET_CPUSUBSET(__set,cpu) = TOPO_CPUSUBSET_VAL(cpu); __set; })

/* displaying cpusets */
#if TOPO_BITS_PER_LONG == 32
#    define TOPO_PRIxCPUSUBSET		"%08lx"
#else
#    define TOPO_PRIxCPUSUBSET		"%016lx"
#endif
#    define TOPO_CPUSUBSET_STRING_LENGTH	(TOPO_BITS_PER_LONG/4)
#    define TOPO_CPUSET_STRING_LENGTH		(TOPO_CPUSUBSET_COUNT*(TOPO_CPUSUBSET_STRING_LENGTH+1))
#    define TOPO_PRIxCPUSET		"s"
#    define TOPO_CPUSET_PRINTF_VALUE(x)	({					\
	char *__buf = alloca(TOPO_CPUSET_STRING_LENGTH+1);			\
	char *__tmp = __buf;							\
	int __i;								\
	*__tmp = '\0';								\
	for(__i=TOPO_CPUSUBSET_COUNT-1; __i>=0; __i--)				\
	  if ((x).s[__i] != 0)							\
	    /* print the whole subset if not empty */				\
	    __tmp += sprintf(__tmp, TOPO_PRIxCPUSUBSET ",", (x).s[__i]);	\
	  else if (__i == 0)							\
	    /* print a single 0 to mark the last subset */			\
	    __tmp += sprintf(__tmp, "0,");					\
	  else if (__tmp != __buf)						\
	    /* print nothing if we haven't printed anything yet */		\
	    *(__tmp++) = ',';							\
	/* remove the ending comma if we printed something */			\
	if (__tmp != __buf)							\
	  *(__tmp-1) = '\0';							\
	/* return the alloca'ted buffer */					\
	__buf;									\
     })



/*  Primitives & macros for building "sets" of cpus. */

/** \brief Initialize CPU set */
void topo_cpuset_init(topo_cpuset_t * set);
#define topo_cpuset_init(m)        topo_cpuset_zero(m)
<commit_msg>Add topo_cpuset_from_string<commit_after>/* Copyright 2009 INRIA, Université Bordeaux 1  */

/* The cpuset API, for use in libtopology itself.  */

#ifndef LIBTOPOLOGY_CPUSET_H
#define LIBTOPOLOGY_CPUSET_H

#include <libtopology/config.h>

#include <stdint.h>
#include <string.h>
#include <strings.h>

/* large cpuset using an array of unsigned long subsets */

/* size and count of subsets within a set */
#    define TOPO_CPUSUBSET_SIZE		(8*sizeof(long))
#    define TOPO_CPUSUBSET_COUNT	((LIBTOPO_NBMAXCPUS+TOPO_CPUSUBSET_SIZE-1)/TOPO_CPUSUBSET_SIZE)
typedef struct { unsigned long s[TOPO_CPUSUBSET_COUNT]; } topo_cpuset_t;

/* extract a subset from a set using an index or a cpu */
#    define TOPO_CPUSUBSET_SUBSET(set,x)	((set).s[x])
#    define TOPO_CPUSUBSET_INDEX(cpu)		((cpu)/(TOPO_CPUSUBSET_SIZE))
#    define TOPO_CPUSUBSET_CPUSUBSET(set,cpu)	TOPO_CPUSUBSET_SUBSET(set,TOPO_CPUSUBSET_INDEX(cpu))

/* predefined subset values */
#    define TOPO_CPUSUBSET_VAL(cpu)	(1UL<<((cpu)%(TOPO_CPUSUBSET_SIZE)))
#    define TOPO_CPUSUBSET_ZERO		0UL
#    define TOPO_CPUSUBSET_FULL		~0UL

/* actual whole-cpuset values */
#    define TOPO_CPUSET_ZERO		(topo_cpuset_t){ .s[0 ... TOPO_CPUSUBSET_COUNT-1] = TOPO_CPUSUBSET_ZERO }
#    define TOPO_CPUSET_FULL		(topo_cpuset_t){ .s[0 ... TOPO_CPUSUBSET_COUNT-1] = TOPO_CPUSUBSET_FULL }
#    define TOPO_CPUSET_CPU(cpu)	({ topo_cpuset_t __set = TOPO_CPUSET_ZERO; TOPO_CPUSUBSET_CPUSUBSET(__set,cpu) = TOPO_CPUSUBSET_VAL(cpu); __set; })

/* displaying cpusets */
#if TOPO_BITS_PER_LONG == 32
#    define TOPO_PRIxCPUSUBSET		"%08lx"
#else
#    define TOPO_PRIxCPUSUBSET		"%016lx"
#endif
#    define TOPO_CPUSUBSET_STRING_LENGTH	(TOPO_BITS_PER_LONG/4)
#    define TOPO_CPUSET_STRING_LENGTH		(TOPO_CPUSUBSET_COUNT*(TOPO_CPUSUBSET_STRING_LENGTH+1))
#    define TOPO_PRIxCPUSET		"s"
#    define TOPO_CPUSET_PRINTF_VALUE(x)	({					\
	char *__buf = alloca(TOPO_CPUSET_STRING_LENGTH+1);			\
	char *__tmp = __buf;							\
	int __i;								\
	*__tmp = '\0';								\
	for(__i=TOPO_CPUSUBSET_COUNT-1; __i>=0; __i--)				\
	  if ((x).s[__i] != 0)							\
	    /* print the whole subset if not empty */				\
	    __tmp += sprintf(__tmp, TOPO_PRIxCPUSUBSET ",", (x).s[__i]);	\
	  else if (__i == 0)							\
	    /* print a single 0 to mark the last subset */			\
	    __tmp += sprintf(__tmp, "0,");					\
	  else if (__tmp != __buf)						\
	    /* print nothing if we haven't printed anything yet */		\
	    *(__tmp++) = ',';							\
	/* remove the ending comma if we printed something */			\
	if (__tmp != __buf)							\
	  *(__tmp-1) = '\0';							\
	/* return the alloca'ted buffer */					\
	__buf;									\
     })

/* parsing a cpuset string */
static __inline__ void
topo_cpuset_from_string(const char * string, topo_cpuset_t * set)
{
  char * current = (char *) string;
  int count=0, i;

  while (*current != '\0') {
    unsigned long val;
    char *next;
    val = strtoul(current, &next, 16);
    /* store subset in order, starting from the end */
    set->s[TOPO_CPUSUBSET_COUNT-1-count] = val;
    count++;
    if (*next != ',')
      break;
    current = next+1;
  }

  /* move subsets back to the beginning and clear the missing subsets */
  memmove(&set->s[0], &set->s[TOPO_CPUSUBSET_COUNT-count], count*sizeof(set->s[0]));
  for(i=count; i<TOPO_CPUSUBSET_COUNT; i++)
    set->s[i] = 0;
}

/*  Primitives & macros for building "sets" of cpus. */

/** \brief Initialize CPU set */
void topo_cpuset_init(topo_cpuset_t * set);
#define topo_cpuset_init(m)        topo_cpuset_zero(m)

{'fraction_non_alphanumeric': 0.12998266897746968, 'fraction_numerical': 0.011816606270679061, 'mean_word_length': 3.4391608391608393, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '941860', 'n_tokens_mistral': 2839, 'n_tokens_neox': 2697, 'n_words': 521}