Deleted Added
full compact
dn_aqm_pie.c (301162) dn_aqm_pie.c (302338)
1/*
2 * PIE - Proportional Integral controller Enhanced AQM algorithm.
3 *
1/*
2 * PIE - Proportional Integral controller Enhanced AQM algorithm.
3 *
4 * $FreeBSD: head/sys/netpfil/ipfw/dn_aqm_pie.c 301162 2016-06-01 20:04:24Z truckman $
4 * $FreeBSD: head/sys/netpfil/ipfw/dn_aqm_pie.c 302338 2016-07-05 00:53:01Z truckman $
5 *
6 * Copyright (C) 2016 Centre for Advanced Internet Architectures,
7 * Swinburne University of Technology, Melbourne, Australia.
8 * Portions of this code were made possible in part by a gift from
9 * The Comcast Innovation Fund.
10 * Implemented by Rasool Al-Saadi <ralsaadi@swin.edu.au>
11 *
12 * Redistribution and use in source and binary forms, with or without

--- 189 unchanged lines hidden (view full) ---

202 */
203static void
204calculate_drop_prob(void *x)
205{
206 int64_t p, prob, oldprob;
207 struct dn_aqm_pie_parms *pprms;
208 struct pie_status *pst = (struct pie_status *) x;
209
5 *
6 * Copyright (C) 2016 Centre for Advanced Internet Architectures,
7 * Swinburne University of Technology, Melbourne, Australia.
8 * Portions of this code were made possible in part by a gift from
9 * The Comcast Innovation Fund.
10 * Implemented by Rasool Al-Saadi <ralsaadi@swin.edu.au>
11 *
12 * Redistribution and use in source and binary forms, with or without

--- 189 unchanged lines hidden (view full) ---

202 */
203static void
204calculate_drop_prob(void *x)
205{
206 int64_t p, prob, oldprob;
207 struct dn_aqm_pie_parms *pprms;
208 struct pie_status *pst = (struct pie_status *) x;
209
210 /* dealing with race condition */
211 if (callout_pending(&pst->aqm_pie_callout)) {
212 /* callout was reset */
213 mtx_unlock(&pst->lock_mtx);
214 return;
215 }
216
217 if (!callout_active(&pst->aqm_pie_callout)) {
218 /* callout was stopped */
219 mtx_unlock(&pst->lock_mtx);
220 mtx_destroy(&pst->lock_mtx);
221 free(x, M_DUMMYNET);
222 //pst->pq->aqm_status = NULL;
223 pie_desc.ref_count--;
224 return;
225 }
226 callout_deactivate(&pst->aqm_pie_callout);
227
228 pprms = pst->parms;
229 prob = pst->drop_prob;
230
231 /* calculate current qdelay */
232 if (pprms->flags & PIE_DEPRATEEST_ENABLED) {
233 pst->current_qdelay = ((uint64_t)pst->pq->ni.len_bytes *
234 pst->avg_dq_time) >> PIE_DQ_THRESHOLD_BITS;
235 }

--- 335 unchanged lines hidden (view full) ---

571 struct pie_status *pst;
572 struct dn_aqm_pie_parms *pprms;
573 int err = 0;
574
575 pprms = q->fs->aqmcfg;
576
577 do { /* exit with break when error occurs*/
578 if (!pprms){
210 pprms = pst->parms;
211 prob = pst->drop_prob;
212
213 /* calculate current qdelay */
214 if (pprms->flags & PIE_DEPRATEEST_ENABLED) {
215 pst->current_qdelay = ((uint64_t)pst->pq->ni.len_bytes *
216 pst->avg_dq_time) >> PIE_DQ_THRESHOLD_BITS;
217 }

--- 335 unchanged lines hidden (view full) ---

553 struct pie_status *pst;
554 struct dn_aqm_pie_parms *pprms;
555 int err = 0;
556
557 pprms = q->fs->aqmcfg;
558
559 do { /* exit with break when error occurs*/
560 if (!pprms){
579 D("AQM_PIE is not configured");
561 DX(2, "AQM_PIE is not configured");
580 err = EINVAL;
581 break;
582 }
583
584 q->aqm_status = malloc(sizeof(struct pie_status),
585 M_DUMMYNET, M_NOWAIT | M_ZERO);
586 if (q->aqm_status == NULL) {
587 D("cannot allocate PIE private data");

--- 22 unchanged lines hidden (view full) ---

610 //DX(2, "aqm_PIE_init");
611
612 } while(0);
613
614 return err;
615}
616
617/*
562 err = EINVAL;
563 break;
564 }
565
566 q->aqm_status = malloc(sizeof(struct pie_status),
567 M_DUMMYNET, M_NOWAIT | M_ZERO);
568 if (q->aqm_status == NULL) {
569 D("cannot allocate PIE private data");

--- 22 unchanged lines hidden (view full) ---

592 //DX(2, "aqm_PIE_init");
593
594 } while(0);
595
596 return err;
597}
598
599/*
600 * Callout function to destroy pie mtx and free PIE status memory
601 */
602static void
603pie_callout_cleanup(void *x)
604{
605 struct pie_status *pst = (struct pie_status *) x;
606
607 mtx_unlock(&pst->lock_mtx);
608 mtx_destroy(&pst->lock_mtx);
609 free(x, M_DUMMYNET);
610 DN_BH_WLOCK();
611 pie_desc.ref_count--;
612 DN_BH_WUNLOCK();
613}
614
615/*
618 * Clean up PIE status for queue 'q'
619 * Destroy memory allocated for PIE status.
620 */
621static int
622aqm_pie_cleanup(struct dn_queue *q)
623{
624
625 if(!q) {

--- 9 unchanged lines hidden (view full) ---

635 D("fs is null or no cfg");
636 return 1;
637 }
638 if (q->fs->aqmfp && q->fs->aqmfp->type !=DN_AQM_PIE) {
639 D("Not PIE fs (%d)", q->fs->fs.fs_nr);
640 return 1;
641 }
642
616 * Clean up PIE status for queue 'q'
617 * Destroy memory allocated for PIE status.
618 */
619static int
620aqm_pie_cleanup(struct dn_queue *q)
621{
622
623 if(!q) {

--- 9 unchanged lines hidden (view full) ---

633 D("fs is null or no cfg");
634 return 1;
635 }
636 if (q->fs->aqmfp && q->fs->aqmfp->type !=DN_AQM_PIE) {
637 D("Not PIE fs (%d)", q->fs->fs.fs_nr);
638 return 1;
639 }
640
641 /*
642 * Free PIE status allocated memory using pie_callout_cleanup() callout
643 * function to avoid any potential race.
644 * We reset aqm_pie_callout to call pie_callout_cleanup() in next 1um. This
645 * stops the scheduled calculate_drop_prob() callout and call pie_callout_cleanup()
646 * which does memory freeing.
647 */
643 mtx_lock(&pst->lock_mtx);
648 mtx_lock(&pst->lock_mtx);
649 callout_reset_sbt(&pst->aqm_pie_callout,
650 SBT_1US, 0, pie_callout_cleanup, pst, 0);
651 q->aqm_status = NULL;
652 mtx_unlock(&pst->lock_mtx);
644
653
645 /* stop callout timer */
646 if (callout_stop(&pst->aqm_pie_callout) || !(pst->sflags & PIE_ACTIVE)) {
647 mtx_unlock(&pst->lock_mtx);
648 mtx_destroy(&pst->lock_mtx);
649 free(q->aqm_status, M_DUMMYNET);
650 q->aqm_status = NULL;
651 pie_desc.ref_count--;
652 return 0;
653 } else {
654 q->aqm_status = NULL;
655 mtx_unlock(&pst->lock_mtx);
656 DX(2, "PIE callout has not been stoped from cleanup!");
657 return EBUSY;
658 }
659 return 0;
660}
661
662/*
663 * Config PIE parameters
664 * also allocate memory for PIE configurations
665 */
666static int

--- 127 unchanged lines hidden ---
654 return 0;
655}
656
657/*
658 * Config PIE parameters
659 * also allocate memory for PIE configurations
660 */
661static int

--- 127 unchanged lines hidden ---