 
	
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH 07 of 10 [RFC]] sched_credit: Let the scheduler know about `node affinity`
 On 11/04/12 14:17, Dario Faggioli wrote: Hey Dario, Sorry for the long delay in reviewing this. Overall I think the approach is good. A few points: This thing of defining "START_STEP" and "END_STEP" seems a bit fragile. I think it would be better to always start at 0, and go until CSCHED_BALANCE_MAX./* + * Node Balancing + */ +#define CSCHED_BALANCE_NODE_AFFINITY 1 +#define CSCHED_BALANCE_CPU_AFFINITY 0 +#define CSCHED_BALANCE_START_STEP CSCHED_BALANCE_NODE_AFFINITY +#define CSCHED_BALANCE_END_STEP CSCHED_BALANCE_CPU_AFFINITY + + + /* + * Let's cache domain's dom->node_affinity here as an + * optimization for a couple of hot paths. In fact, + * knowing whether or not dom->node_affinity has changed + * would allow us to avoid rebuilding node_affinity_cpumask + * (below) duing node balancing and/or scheduling. + */ + nodemask_t node_affinity_cache; + /* Basing on what dom->node_affinity says, + * on what CPUs would we like to run most? */ + cpumask_t node_affinity_cpumask; I think the comments here need to be more clear. The main points are:* node_affinity_cpumask is the dom->node_affinity translated from a nodemask into a cpumask * Because doing the nodemask -> cpumask translation may be expensive, node_affinity_cache stores the last translated value, so we can avoid doing the translation if nothing has changed. I don't like this. For one, it's fragile; if for some reason you switched NODE_AFFINITY and CPU_AFFINITY above, suddenly this loop would go the wrong direction.+#define csched_balance(__step) \ + for ( (__step) = CSCHED_BALANCE_START_STEP; \ + (__step)>= CSCHED_BALANCE_END_STEP; \ + (__step)-- ) I don't think there's any reason not to just use "for(step=0; step < CSCHED_BALANCE_MAX; step++)" -- it's not ugly and it means you know exactly what's going on without having to go search for the macro. This needs to be clearer -- vcpu-affinity doesn't have anything to do with this function, and there's nothing "sort-of" about the conversion. :-)+ +/* + * Sort-of conversion between node-affinity and vcpu-affinity for the domain, + * i.e., a cpumask containing all the cpus from all the set nodes in the + * node-affinity mask of the domain. I think you mean to say, "Create a cpumask from the node affinity mask." + * + * Notice that we completely forget about serializing this (both here and + * in the various sites where node_affinity_cpumask is used) against + * d->node_affinity_lock. That would be hard to do properly, as that lock + * is a non IRQ-safe one, and it would be nearly impossible to access it + * from the scheduling code. However, although this leaves some room for + * races with code paths that updates d->node_affinity, it all should still + * be fine, considering: + * (1) d->node_affinity updates are going to be quite rare; + * (2) this balancing logic is kind-of "best effort" anyway; + * (3) given (1), any inconsistencies are likely to be fixed by the next + * call to this same function without risking going into instability. + * + * XXX Validate (via testing/benchmarking) whether this is true, as it + * likely sounds to be, or it causes unexpected issues. Ack. Hmm -- this mechanism seems kind of fragile.  It seems like returning -1 
or something, and having the caller call "continue", would be easier for 
future coders (potentially you or I) to reason about.Beware of early optimization. :-) Just make sure to mark this down for something to look at for profiling.+ /* + * XXX As of now (with only two possible steps, this is easy and readable + * enough. If more steps become necessary at some point in time, we + * can keep an array of cpumask_t in dom_data and return the proper + * element via step-indexing such an array. Of course, we can turn + * this like that even right now... Thoughts? + */ I don't see any reason to make this into a function -- it's only called 
once, and it's not that long.  Unless you're concerned about too many 
indentations making the lines too short?Again, I'd make this a for() loop. We might as well do what you've got here, unless it's likely to produce 
garbage.  This isn't exactly a hot path. :-)Other than that, looks good -- Thanks! -George _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel 
 
 | 
|  | Lists.xenproject.org is hosted with RackSpace, monitoring our |