Lines Matching defs:cap

43  * A CPU cap can be set on any project or any zone. Zone CPU cap limits the CPU
44 * usage for all projects running inside the zone. If the zone CPU cap is set
45 * below the project CPU cap, the latter will have no effect.
49 * with a cap. Such threads will start running again only when CPU usage drops
50 * below the cap level. Each zone and each project has its own wait queue.
52 * When CPU cap is set, the kernel continously keeps track of CPU time used by
55 * cap, LWPs running in the user-land (when they are not holding any critical
57 * zone's CPU usage drops below the cap.
64 * When the current CPU usage is above the cap, a project or zone is considered
96 * one per cent. If CPU usage drops below cap levels, threads on the wait queue
108 * capped_projects list if its zone has a cap.
112 * Remove the association between the specified project and its cap.
117 * Set project cap of the specified project to the specified value. Setting the
118 * value to NOCAP is equivalent to removing the cap.
122 * Set zone cap of the specified zone to the specified value. Setting the value
123 * to NOCAP is equivalent to removing the cap.
127 * Remove the association between the zone and its cap.
134 * project or zone is exceeding its cap. Also sets TS_PROJWAITQ or TS_ZONEWAITQ
159 * cap are not going to disappear while thread lock is held.
165 * contend for the same cache line doing cap usage updates.
169 * caps_lock protects list of capped projects and zones, changes in the cap
172 * Changing zone caps also sets cpucaps_busy to avoid races when a zone cap is
173 * modified in parallel. This can be per-zone cap flag, but we don't keep any
174 * cap state for now.
264 cpucap_t *cap = kmem_zalloc(sizeof (cpucap_t), KM_SLEEP);
266 DISP_LOCK_INIT(&cap->cap_usagelock);
267 waitq_init(&cap->cap_waitq);
269 return (cap);
276 cap_free(cpucap_t *cap)
278 if (cap == NULL)
282 * This cap should not be active
284 ASSERT(!list_link_active(&cap->cap_link));
285 ASSERT(cap->cap_value == 0);
286 ASSERT(!DISP_LOCK_HELD(&cap->cap_usagelock));
288 waitq_fini(&cap->cap_waitq);
289 DISP_LOCK_DESTROY(&cap->cap_usagelock);
291 kmem_free(cap, sizeof (cpucap_t));
295 * Activate cap - insert into active list and unblock its
300 cap_enable(list_t *l, cpucap_t *cap, hrtime_t value)
307 ASSERT(!CAP_ENABLED(cap));
308 ASSERT(!list_link_active(&cap->cap_link));
310 list_insert_tail(l, cap);
311 cap->cap_below = cap->cap_above = 0;
312 cap->cap_maxusage = 0;
313 cap->cap_usage = 0;
314 cap->cap_value = value;
315 waitq_unblock(&cap->cap_waitq);
323 * Deactivate cap
326 * - Remove cap from list l.
332 cap_disable(list_t *l, cpucap_t *cap)
339 ASSERT(list_link_active(&cap->cap_link));
340 ASSERT(CAP_ENABLED(cap));
342 waitq_block(&cap->cap_waitq);
343 list_remove(l, cap);
348 cap->cap_value = 0;
349 cap->cap_project = NULL;
350 cap->cap_zone = NULL;
351 if (cap->cap_kstat != NULL) {
352 kstat_delete(cap->cap_kstat);
353 cap->cap_kstat = NULL;
359 * Enable cap for a project kpj
360 * It is safe to enable already enabled project cap.
366 cpucap_t *cap = kpj->kpj_cpucap;
369 ASSERT(cap != NULL);
371 if (CAP_DISABLED(cap)) {
372 ASSERT(cap->cap_kstat == NULL);
373 cap_enable(&capped_projects, cap, value);
374 cap->cap_project = kpj;
375 cap->cap_zone = kpj->kpj_zone;
378 * Create cap kstats
380 if ((cap->cap_kstat = rctl_kstat_create_project(kpj, "cpucaps",
384 cap->cap_kstat->ks_data_size +=
385 strlen(cap->cap_zone->zone_name) + 1;
386 cap->cap_kstat->ks_lock = &cap_kstat_lock;
387 cap->cap_kstat->ks_data = &cap_kstat;
388 cap->cap_kstat->ks_update = cap_kstat_update;
389 cap->cap_kstat->ks_private = cap;
390 kstat_install(cap->cap_kstat);
396 * Disable project cap.
397 * It is safe to disable already disabled project cap.
403 cpucap_t *cap = kpj->kpj_cpucap;
406 ASSERT(cap != NULL);
407 ASSERT(cap->cap_project == kpj);
409 if (CAP_ENABLED(cap))
410 cap_disable(&capped_projects, cap);
414 * Enable cap for a zone
415 * It is safe to enable already enabled zone cap.
421 cpucap_t *cap = zone->zone_cpucap;
424 ASSERT(cap != NULL);
426 if (CAP_DISABLED(cap)) {
427 ASSERT(cap->cap_kstat == NULL);
428 cap_enable(&capped_zones, cap, value);
429 cap->cap_zone = zone;
432 * Create cap kstats
434 if ((cap->cap_kstat = rctl_kstat_create_zone(zone, "cpucaps",
438 cap->cap_kstat->ks_data_size +=
439 strlen(cap->cap_zone->zone_name) + 1;
440 cap->cap_kstat->ks_lock = &cap_kstat_lock;
441 cap->cap_kstat->ks_data = &cap_kstat;
442 cap->cap_kstat->ks_update = cap_kstat_update;
443 cap->cap_kstat->ks_private = cap;
444 kstat_install(cap->cap_kstat);
450 * Disable zone cap.
451 * It is safe to disable already disabled zone cap.
457 cpucap_t *cap = zone->zone_cpucap;
460 ASSERT(cap != NULL);
461 ASSERT(cap->cap_zone == zone);
463 if (CAP_ENABLED(cap))
464 cap_disable(&capped_zones, cap);
474 cpucap_t *cap;
478 for (cap = list_head(l); cap != NULL; cap = list_next(l, cap)) {
479 (*cb)(cap, cpucap_walk_gen);
486 * If cap limit is not reached, make one thread from wait queue runnable.
493 cap_poke_waitq(cpucap_t *cap, int64_t gen)
497 if (cap->cap_usage >= cap->cap_value) {
498 cap->cap_above++;
500 waitq_t *wq = &cap->cap_waitq;
502 cap->cap_below++;
510 * The callback function called for every cap on capped_projects list.
511 * Decay cap usage by CAP_DECAY_FACTOR
512 * Add this cap project usage to its zone usage.
513 * Kick off a thread from the cap waitq if cap is not reached.
516 cap_project_usage_walker(cpucap_t *cap, int64_t gen)
518 zone_t *zone = cap->cap_zone;
519 hrtime_t cap_usage = cap->cap_usage;
522 ASSERT(cap->cap_project->kpj_cpucap == cap);
523 ASSERT(zone == cap->cap_project->kpj_zone);
524 ASSERT(CAP_ENABLED(cap));
530 cap_poke_waitq(cap, 0);
563 disp_lock_enter(&cap->cap_usagelock);
564 cap->cap_usage -= ROUND_SCALE(cap_usage, CAP_DECAY_FACTOR);
565 disp_lock_exit(&cap->cap_usagelock);
588 * The function is called for each project in a zone when the zone cap is
589 * modified. It enables project caps if zone cap is enabled and disables if the
590 * zone cap is disabled and project doesn't have its own cap.
607 * This is the first time any cap was established for this
648 * Set zone cap to cap_val
649 * If cap_val is equal to NOCAP, disable zone cap.
651 * If this is the first time a cap is set on a zone, allocate cpucap structure
657 cpucap_t *cap = NULL;
668 * Nothing to do if trying to disable a cap on a zone when caps are off
669 * or a zone which does not have a cap yet.
675 cap = cap_alloc();
689 zone->zone_cpucap = cap;
690 } else if (cap != NULL) {
691 cap_free(cap);
694 cap = zone->zone_cpucap;
700 if (value == cap->cap_value) {
706 * Clear cap statistics since the cap value itself changes.
708 cap->cap_above = cap->cap_below = 0;
712 if (CAP_ENABLED(cap)) {
714 * Remove cap for the zone
721 * unless they have their own cap.
724 cap_project_zone_modify_walker, cap);
729 } else if (CAP_DISABLED(cap)) {
731 * Set a cap on a zone which previously was not capped.
738 * Enable cap for all projects belonging to this zone.
741 cap_project_zone_modify_walker, cap);
749 cap->cap_value = value;
760 * The project is going away so disable its cap.
776 * The zone is going away, so disable its cap.
796 * its zone has a cap.
801 cpucap_t *cap = NULL;
807 * This project was never capped before, so allocate its cap structure.
810 cap = cap_alloc();
817 kpj->kpj_cpucap = cap;
818 } else if (cap != NULL) {
819 cap_free(cap);
829 * Set project cap to cap_val
830 * If cap_val is equal to NOCAP, disable project cap.
832 * If this is the first time a cap is set on a project, allocate cpucap
839 cpucap_t *cap = NULL;
850 * Nothing to do if trying to disable project cap and caps are not
851 * enabled or if trying to disable cap on a project that does not have
852 * cap enabled.
859 * This project was never capped before, so allocate its cap
862 cap = cap_alloc();
871 kpj->kpj_cpucap = cap;
872 } else if (cap != NULL) {
873 cap_free(cap);
877 * Get the actual pointer to the project cap.
879 cap = kpj->kpj_cpucap;
887 if (value == cap->cap_value) {
893 * Clear cap statistics since the cap value itself changes.
895 cap->cap_above = cap->cap_below = 0;
896 cap->cap_maxusage = 0;
900 * Enable this cap if it is not already enabled.
902 if (CAP_DISABLED(cap))
905 cap->cap_value = value;
906 } else if (CAP_ENABLED(cap)) {
908 * User requested to drop a cap on the project. If it is part of
909 * capped zone, keep the cap and set the value to MAX_USAGE,
910 * otherwise disable the cap.
913 cap->cap_value = MAX_USAGE;
924 * Get cap usage.
927 cap_get(cpucap_t *cap)
929 return (cap != NULL ? (rctl_qty_t)(cap->cap_usage / cap_tick_cost) : 0);
958 * It is possible that the project cap is being disabled while this routine is
987 cpucap_t *cap = kpj->kpj_cpucap;
992 disp_lock_enter_high(&cap->cap_usagelock);
993 cap->cap_usage += usage_delta;
996 if (cap->cap_usage < 0)
997 cap->cap_usage = MAX_USAGE - 1;
999 disp_lock_exit_high(&cap->cap_usagelock);
1005 if (cap->cap_usage > cap->cap_maxusage)
1006 cap->cap_maxusage = cap->cap_usage;
1012 * penalized because its project or zone is exceeding its cap. Also sets
1015 * It is possible that the project cap is being disabled while this routine is
1083 * It is possible that by the time we enter cpucaps_enforce() the cap is already
1121 * Convert internal cap statistics into values exported by cap kstat.
1127 cpucap_t *cap = ksp->ks_private;
1129 char *zonename = cap->cap_zone->zone_name;
1135 ROUND_SCALE(cap->cap_value, cap_tick_cost);
1137 ROUND_SCALE(cap->cap_usage, cap_tick_cost);
1139 ROUND_SCALE(cap->cap_maxusage, cap_tick_cost);
1140 capsp->cap_nwait.value.ui64 = cap->cap_waitq.wq_count;
1141 capsp->cap_below.value.ui64 = ROUND_SCALE(cap->cap_below, tick_sec);
1142 capsp->cap_above.value.ui64 = ROUND_SCALE(cap->cap_above, tick_sec);