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;
}
* 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;
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;
}
/*
- * 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;
}