Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F161009206
D57939.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
8 KB
Referenced Files
None
Subscribers
None
D57939.diff
View Options
Index: sys/kern/subr_hmp.c
===================================================================
--- sys/kern/subr_hmp.c
+++ sys/kern/subr_hmp.c
@@ -16,7 +16,6 @@
/* System-wide CPU capability information */
struct hmp hmp_state = {
- .total_capacity = 0,
.has_scores = false,
};
@@ -62,8 +61,7 @@
* Default capacity provider.
*
* Always wins if nothing else probes: every CPU gets HMP_CAPACITY_DEFAULT,
- * which collapses HMP decisions down to "any CPU is fine." There is no
- * default score provider; absence of scores is a valid state.
+ * which collapses HMP decisions down to "any CPU is fine."
*/
static int
@@ -95,23 +93,45 @@
HMP_CAPACITY_PROVIDER_DECLARE(default, hmp_default_cap_provider);
/*
- * Initialization
+ * Default score provider.
+ *
+ * Always wins if nothing else probes: every CPU gets HMP_SCORE_DEFAULT,
+ * which collapses HMP decisions down to "any CPU is fine."
*/
-static void
-hmp_set_total_capacity(void)
+static int
+hmp_default_score_probe(void)
+{
+ return (0);
+}
+
+static int
+hmp_default_score_init(void)
{
struct hmp_pcpu *hp;
int cpu;
- hmp_state.total_capacity = 0;
-
CPU_FOREACH(cpu) {
hp = DPCPU_ID_PTR(cpu, hmp_pcpu);
- hmp_state.total_capacity += hp->capacity;
+ hmp_set_score(hp, HMP_SCORE_PERF, HMP_SCORE_DEFAULT);
+ hmp_set_score(hp, HMP_SCORE_EFF, HMP_SCORE_DEFAULT);
}
+
+ return (0);
}
+static struct hmp_score_provider hmp_default_score_provider = {
+ .name = "default",
+ .priority = 0,
+ .probe = hmp_default_score_probe, /* always true */
+ .init = hmp_default_score_init,
+};
+HMP_SCORE_PROVIDER_DECLARE(default, hmp_default_score_provider);
+
+/*
+ * Initialization
+ */
+
static void
hmp_init_capacity(void)
{
@@ -141,7 +161,6 @@
("hmp: no capacity provider init succeeded, not even default"));
best->active = true;
hmp_active_cap_provider = best;
- hmp_set_total_capacity();
}
static void
@@ -184,108 +203,6 @@
}
SYSINIT(hmp, SI_SUB_SMP + 1, SI_ORDER_ANY, hmp_init, NULL);
-/*
- * Helper functions for scheduler
- */
-
-/*
- * Fall back for hmp_best_cpu in case processor doesn't support dynamic
- * score update. Takes O(n).
- *
- * TODO: Precalculate cpu with highest capacity on boot after initialization.
- */
-int
-hmp_highest_capacity_cpu(const cpuset_t *mask)
-{
- struct hmp_pcpu *hp;
- hmp_score_t best_cap;
- int best_cpu, cpu;
-
- best_cpu = -1;
- best_cap = 0;
-
- CPU_FOREACH(cpu) {
- if (mask != NULL && !CPU_ISSET(cpu, mask))
- continue;
- hp = DPCPU_ID_PTR(cpu, hmp_pcpu);
- if (hp->capacity > best_cap) {
- best_cap = hp->capacity;
- best_cpu = cpu;
- }
- }
-
- return (best_cpu);
-}
-
-int
-hmp_lowest_capacity_cpu(const cpuset_t *mask)
-{
- struct hmp_pcpu *hp;
- hmp_score_t best_cap;
- int best_cpu, cpu;
-
- best_cpu = -1;
- best_cap = 0;
-
- CPU_FOREACH(cpu) {
- if (mask != NULL && !CPU_ISSET(cpu, mask))
- continue;
- hp = DPCPU_ID_PTR(cpu, hmp_pcpu);
- if (best_cpu == -1 || hp->capacity < best_cap) {
- best_cap = hp->capacity;
- best_cpu = cpu;
- }
- }
-
- return (best_cpu);
-}
-
-/*
- * Find CPU with best score for given class and capability for thread
- * placement. Fall backs to capacity if scores are not provided. Takes O(n).
- *
- * It is possible that a score of previously read cpu is updated by a provider
- * while this function is still traversing remaining cpus, but the effect is
- * negligible.
- *
- * TODO: If this brings severe performance degradation, score providers should
- * maintain and update index everytime new information is fed and
- * the scheduler should use the index which takes O(1).
- */
-int
-hmp_best_cpu(const cpuset_t *mask, enum score_type st)
-{
- struct hmp_pcpu *hp;
- hmp_score_t best_score;
- int best_cpu, cpu;
-
- if (!hmp_state.has_scores) {
- switch (st) {
- case HMP_SCORE_PERF:
- return (hmp_highest_capacity_cpu(mask));
- case HMP_SCORE_EFF:
- return (hmp_lowest_capacity_cpu(mask));
- default:
- panic("invalid score type");
- }
- }
-
- best_cpu = -1;
- best_score = 0;
-
- CPU_FOREACH(cpu) {
- if (mask != NULL && !CPU_ISSET(cpu, mask))
- continue;
- hp = DPCPU_ID_PTR(cpu, hmp_pcpu);
- if (hp->scores[st] > best_score) {
- best_score = hp->scores[st];
- best_cpu = cpu;
- }
- }
-
- return (best_cpu);
-}
-
/*
* Sysctls
*/
@@ -301,17 +218,6 @@
return (sysctl_handle_int(oidp, &v, 0, req));
}
-static int
-hmp_sysctl_capacity_percent(SYSCTL_HANDLER_ARGS)
-{
- struct hmp_pcpu *hp;
- unsigned int v;
-
- hp = DPCPU_ID_PTR(arg2, hmp_pcpu);
- v = HMP_CAPACITY_NORMAL_TO_PERCENT(hp->capacity);
- return (sysctl_handle_int(oidp, &v, 0, req));
-}
-
static int
hmp_sysctl_score(SYSCTL_HANDLER_ARGS)
{
@@ -367,10 +273,6 @@
static SYSCTL_NODE(_kern, OID_AUTO, hmp, CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
"Heterogeneous multi-processing state");
-SYSCTL_U32(_kern_hmp, OID_AUTO, total_capacity, CTLFLAG_RD,
- &hmp_state.total_capacity, 0,
- "Sum of per-CPU capacities (normalized to HMP_CAPACITY_SCALE)");
-
SYSCTL_BOOL(_kern_hmp, OID_AUTO, has_scores, CTLFLAG_RD,
&hmp_state.has_scores, 0,
"True if a score provider is supplying dynamic perf/eff scores");
@@ -411,11 +313,6 @@
hmp_sysctl_capacity, "IU",
"Static capacity (0-HMP_CAPACITY_SCALE)");
- SYSCTL_ADD_PROC(NULL, cpu_children, OID_AUTO, "capacity_percent",
- CTLTYPE_UINT | CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, cpu,
- hmp_sysctl_capacity_percent, "IU",
- "Static capacity as a percentage of the scale");
-
cpu_score_node = SYSCTL_ADD_NODE(NULL, cpu_children, OID_AUTO,
"score", CTLFLAG_RD | CTLFLAG_MPSAFE, NULL,
"Per-CPU dynamic scores");
Index: sys/sys/hmp.h
===================================================================
--- sys/sys/hmp.h
+++ sys/sys/hmp.h
@@ -25,13 +25,8 @@
#define HMP_CAPACITY_MAX HMP_CAPACITY_SCALE
#define HMP_CAPACITY_DEFAULT HMP_CAPACITY_MAX
-/* Capacity normalization macro functions */
-#define HMP_CAPACITY_NORMAL_FROM(x, y) (((x) * HMP_CAPACITY_SCALE) / (y))
-#define HMP_CAPACITY_NORMAL_FROM_255(x) HMP_CAPACITY_NORMAL_FROM((x), 255)
-#define HMP_CAPACITY_NORMAL_FROM_1024(x) HMP_CAPACITY_NORMAL_FROM((x), 1024)
-
-#define HMP_CAPACITY_NORMAL_TO(x, y) (((x) * (y)) / HMP_CAPACITY_SCALE)
-#define HMP_CAPACITY_NORMAL_TO_PERCENT(x) HMP_CAPACITY_NORMAL_TO((x), 100)
+#define HMP_SCORE_MAX 1024
+#define HMP_SCORE_DEFAULT HMP_SCORE_MAX
/*
* Score type
@@ -51,22 +46,25 @@
*/
typedef uint32_t hmp_capacity_t;
+/* Capacity normalization macro functions */
+#define HMP_CAPACITY_NORMAL_FROM(x, y) (((hmp_capacity_t)(y) * HMP_CAPACITY_SCALE) / (hmp_capacity_t)(x))
+
/*
* CPU score type
- * This doesn't need to be normalized.
+ * The range of this value is 0-1024.
+ * The higher the performance, the larger the value becomes,
+ * and normalization is not required.
*/
typedef uint32_t hmp_score_t;
/*
* System-wide CPU capability state - initialized on boot
*
- * total_capacity is populated once the capacity provider finishes init().
* has_scores is set to true once a score provider has won selection and
* finished init(); when false, the scheduler must fall back to capacity-only
* placement decisions.
*/
struct hmp {
- hmp_capacity_t total_capacity; /* Precalculated for scheduler */
bool has_scores; /* Runtime updates available */
};
extern struct hmp hmp_state;
@@ -83,6 +81,12 @@
/*
* Accessors
*/
+static inline hmp_capacity_t
+hmp_get_capacity(struct hmp_pcpu *hp, int cpu)
+{
+ return hp->capacity;
+}
+
static inline hmp_score_t
hmp_get_score(struct hmp_pcpu *hp, enum score_type st)
{
@@ -110,7 +114,7 @@
/*
* Capacity provider
*
- * Populate the static per-CPU capacity field and hmp_state.total_capacity.
+ * Populate the static per-CPU capacity field.
* Exactly one capacity provider wins at boot (highest priority among
* those whose probe() returns true).
*/
@@ -169,13 +173,6 @@
SYSINIT(hmp_score_provider_##name, SI_SUB_SMP, SI_ORDER_ANY, \
hmp_score_provider_##name##_register, NULL)
-/*
- * Helper functions for scheduler
- */
-int hmp_highest_capacity_cpu(const cpuset_t *mask);
-int hmp_lowest_capacity_cpu(const cpuset_t *mask);
-int hmp_best_cpu(const cpuset_t *mask, enum score_type st);
-
#endif /* HMP */
#endif /* !LOCORE */
#endif /* _KERNEL */
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Jun 30, 7:54 PM (17 h, 54 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34520493
Default Alt Text
D57939.diff (8 KB)
Attached To
Mode
D57939: hmp(4): Interface changes for sched_ule(4) integration
Attached
Detach File
Event Timeline
Log In to Comment