xnu-6153.61.1.tar.gz
[apple/xnu.git] / osfmk / kern / ledger.c
index a0d9258723e56353e20ea92345d272f593fa152e..e905ee666a1862db6fb2c6e3d12ab29bb1feaf5d 100644 (file)
@@ -448,7 +448,7 @@ ledger_instantiate(ledger_template_t template, int entry_type)
                le->le_credit        = 0;
                le->le_debit         = 0;
                le->le_limit         = LEDGER_LIMIT_INFINITY;
-               le->le_warn_level    = LEDGER_LIMIT_INFINITY;
+               le->le_warn_percent  = LEDGER_PERCENT_NONE;
                le->_le.le_refill.le_refill_period = 0;
                le->_le.le_refill.le_last_refill   = 0;
        }
@@ -521,7 +521,8 @@ warn_level_exceeded(struct ledger_entry *le)
         * use positive limits.
         */
        balance = le->le_credit - le->le_debit;
-       if ((le->le_warn_level != LEDGER_LIMIT_INFINITY) && (balance > le->le_warn_level)) {
+       if (le->le_warn_percent != LEDGER_PERCENT_NONE &&
+           ((balance > (le->le_limit * le->le_warn_percent) >> 16))) {
                return 1;
        }
        return 0;
@@ -987,9 +988,9 @@ ledger_set_limit(ledger_t ledger, int entry, ledger_amount_t limit,
                assert(warn_level_percentage <= 100);
                assert(limit > 0); /* no negative limit support for warnings */
                assert(limit != LEDGER_LIMIT_INFINITY); /* warn % without limit makes no sense */
-               le->le_warn_level = (le->le_limit * warn_level_percentage) / 100;
+               le->le_warn_percent = warn_level_percentage * (1u << 16) / 100;
        } else {
-               le->le_warn_level = LEDGER_LIMIT_INFINITY;
+               le->le_warn_percent = LEDGER_PERCENT_NONE;
        }
 
        return KERN_SUCCESS;
@@ -1145,12 +1146,12 @@ ledger_disable_callback(ledger_t ledger, int entry)
        }
 
        /*
-        * le_warn_level is used to indicate *if* this ledger has a warning configured,
+        * le_warn_percent is used to indicate *if* this ledger has a warning configured,
         * in addition to what that warning level is set to.
         * This means a side-effect of ledger_disable_callback() is that the
         * warning level is forgotten.
         */
-       ledger->l_entries[entry].le_warn_level = LEDGER_LIMIT_INFINITY;
+       ledger->l_entries[entry].le_warn_percent = LEDGER_PERCENT_NONE;
        flag_clear(&ledger->l_entries[entry].le_flags, LEDGER_ACTION_CALLBACK);
        return KERN_SUCCESS;
 }