[CRIU] [PATCH 04/15] cpuinfo: x86 -- Add local copy of CpuinfoEntry

Cyrill Gorcunov gorcunov at gmail.com
Tue Sep 23 11:17:06 PDT 2014


On Tue, Sep 23, 2014 at 10:04:25PM +0400, Pavel Emelyanov wrote:
> >  
> > +static CpuinfoEntry cpu_info = CPUINFO_ENTRY__INIT;
> > +static CpuinfoX86Entry cpu_x86_info = CPUINFO_X86_ENTRY__INIT;
> > +static CpuinfoX86Entry *cpu_x86_info_ptr = &cpu_x86_info;
> 
> I don't get why we need this thing always at hands. Why not
> just allocate one on demand?

Static allocs are faster than on-demand.

> 
> > +
> >  const char * const x86_cap_flags[NCAPINTS_BITS] = {
> >  	[X86_FEATURE_FPU]		= "fpu",
> >  	[X86_FEATURE_CX8]		= "cx8",
> > @@ -106,8 +113,22 @@ static int proc_cpuinfo_match(char *tok)
> >  	return 0;
> >  }
> >  
> > +#define protobuf_features_words (sizeof(cpu_features) / sizeof(cpu_x86_info.features[0]))
> > +
> > +static void cpu_init_protobuf(void)
> > +{
> > +	cpu_info.x86_entry = &cpu_x86_info_ptr;
> > +	cpu_info.n_x86_entry = 1;
> > +	cpu_info.id = 1;
> > +
> > +	cpu_x86_info.n_features = protobuf_features_words;
> > +	cpu_x86_info.features = (void *)cpu_features;
> 
> Why not initialize this at declaration time?

There is no easy way. The CPUINFO_ENTRY__INIT is provided us
by protobuf-c compiler. Sure I can init it by hands but this
might become a problem once protobuf file is changed or protobuf-c
updated.

	Cyrill


More information about the CRIU mailing list