Deleted Added
full compact
sched_ule.c (116377) sched_ule.c (116463)
1/*-
2 * Copyright (c) 2002-2003, Jeffrey Roberson <jeff@freebsd.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2002-2003, Jeffrey Roberson <jeff@freebsd.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/kern/sched_ule.c 116377 2003-06-15 04:14:25Z jeff $");
28__FBSDID("$FreeBSD: head/sys/kern/sched_ule.c 116463 2003-06-17 06:39:51Z jeff $");
29
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/kernel.h>
33#include <sys/ktr.h>
34#include <sys/lock.h>
35#include <sys/mutex.h>
36#include <sys/proc.h>

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

146 * These determine the interactivity of a process.
147 *
148 * SLP_RUN_MAX: Maximum amount of sleep time + run time we'll accumulate
149 * before throttling back.
150 * SLP_RUN_THROTTLE: Divisor for reducing slp/run time.
151 * INTERACT_MAX: Maximum interactivity value. Smaller is better.
152 * INTERACT_THRESH: Threshhold for placement on the current runq.
153 */
29
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/kernel.h>
33#include <sys/ktr.h>
34#include <sys/lock.h>
35#include <sys/mutex.h>
36#include <sys/proc.h>

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

146 * These determine the interactivity of a process.
147 *
148 * SLP_RUN_MAX: Maximum amount of sleep time + run time we'll accumulate
149 * before throttling back.
150 * SLP_RUN_THROTTLE: Divisor for reducing slp/run time.
151 * INTERACT_MAX: Maximum interactivity value. Smaller is better.
152 * INTERACT_THRESH: Threshhold for placement on the current runq.
153 */
154#define SCHED_SLP_RUN_MAX ((hz / 4) << 10)
154#define SCHED_SLP_RUN_MAX ((hz * 2) << 10)
155#define SCHED_SLP_RUN_THROTTLE (2)
156#define SCHED_INTERACT_MAX (100)
157#define SCHED_INTERACT_HALF (SCHED_INTERACT_MAX / 2)
158#define SCHED_INTERACT_THRESH (20)
159
160/*
161 * These parameters and macros determine the size of the time slice that is
162 * granted to each thread.

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

226struct kseq kseq_cpu;
227#define KSEQ_SELF() (&kseq_cpu)
228#define KSEQ_CPU(x) (&kseq_cpu)
229#endif
230
231static void sched_slice(struct kse *ke);
232static void sched_priority(struct ksegrp *kg);
233static int sched_interact_score(struct ksegrp *kg);
155#define SCHED_SLP_RUN_THROTTLE (2)
156#define SCHED_INTERACT_MAX (100)
157#define SCHED_INTERACT_HALF (SCHED_INTERACT_MAX / 2)
158#define SCHED_INTERACT_THRESH (20)
159
160/*
161 * These parameters and macros determine the size of the time slice that is
162 * granted to each thread.

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

226struct kseq kseq_cpu;
227#define KSEQ_SELF() (&kseq_cpu)
228#define KSEQ_CPU(x) (&kseq_cpu)
229#endif
230
231static void sched_slice(struct kse *ke);
232static void sched_priority(struct ksegrp *kg);
233static int sched_interact_score(struct ksegrp *kg);
234static void sched_interact_update(struct ksegrp *kg);
234void sched_pctcpu_update(struct kse *ke);
235int sched_pickcpu(void);
236
237/* Operations on per processor queues */
238static struct kse * kseq_choose(struct kseq *kseq);
239static void kseq_setup(struct kseq *kseq);
240static void kseq_add(struct kseq *kseq, struct kse *ke);
241static void kseq_rem(struct kseq *kseq, struct kse *ke);

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

613 ke, ke->ke_slice, kg->kg_nice, kseq->ksq_nicemin,
614 kseq->ksq_loads[PRI_TIMESHARE], SCHED_INTERACTIVE(kg));
615
616 /*
617 * Check to see if we need to scale back the slp and run time
618 * in the kg. This will cause us to forget old interactivity
619 * while maintaining the current ratio.
620 */
235void sched_pctcpu_update(struct kse *ke);
236int sched_pickcpu(void);
237
238/* Operations on per processor queues */
239static struct kse * kseq_choose(struct kseq *kseq);
240static void kseq_setup(struct kseq *kseq);
241static void kseq_add(struct kseq *kseq, struct kse *ke);
242static void kseq_rem(struct kseq *kseq, struct kse *ke);

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

614 ke, ke->ke_slice, kg->kg_nice, kseq->ksq_nicemin,
615 kseq->ksq_loads[PRI_TIMESHARE], SCHED_INTERACTIVE(kg));
616
617 /*
618 * Check to see if we need to scale back the slp and run time
619 * in the kg. This will cause us to forget old interactivity
620 * while maintaining the current ratio.
621 */
621 if ((kg->kg_runtime + kg->kg_slptime) > SCHED_SLP_RUN_MAX) {
622 kg->kg_runtime /= SCHED_SLP_RUN_THROTTLE;
623 kg->kg_slptime /= SCHED_SLP_RUN_THROTTLE;
624 }
625 CTR4(KTR_ULE, "Slp vs Run(2) %p (Slp %d, Run %d, Score %d)",
626 ke, kg->kg_slptime >> 10, kg->kg_runtime >> 10,
627 sched_interact_score(kg));
622 sched_interact_update(kg);
628
629 return;
630}
631
623
624 return;
625}
626
627static void
628sched_interact_update(struct ksegrp *kg)
629{
630 if ((kg->kg_runtime + kg->kg_slptime) > SCHED_SLP_RUN_MAX) {
631 kg->kg_runtime = (kg->kg_runtime / 5) * 4;
632 kg->kg_slptime = (kg->kg_slptime / 5) * 4;
633 }
634}
635
632static int
633sched_interact_score(struct ksegrp *kg)
634{
635 int div;
636
637 if (kg->kg_runtime > kg->kg_slptime) {
638 div = max(1, kg->kg_runtime / SCHED_INTERACT_HALF);
639 return (SCHED_INTERACT_HALF +

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

831 */
832 if (td->td_slptime) {
833 struct ksegrp *kg;
834 int hzticks;
835
836 kg = td->td_ksegrp;
837 hzticks = ticks - td->td_slptime;
838 kg->kg_slptime += hzticks << 10;
636static int
637sched_interact_score(struct ksegrp *kg)
638{
639 int div;
640
641 if (kg->kg_runtime > kg->kg_slptime) {
642 div = max(1, kg->kg_runtime / SCHED_INTERACT_HALF);
643 return (SCHED_INTERACT_HALF +

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

835 */
836 if (td->td_slptime) {
837 struct ksegrp *kg;
838 int hzticks;
839
840 kg = td->td_ksegrp;
841 hzticks = ticks - td->td_slptime;
842 kg->kg_slptime += hzticks << 10;
843 sched_interact_update(kg);
839 sched_priority(kg);
844 sched_priority(kg);
845 if (td->td_kse)
846 sched_slice(td->td_kse);
840 CTR2(KTR_ULE, "wakeup kse %p (%d ticks)",
841 td->td_kse, hzticks);
842 td->td_slptime = 0;
843 }
844 setrunqueue(td);
845 if (td->td_priority < curthread->td_priority)
846 curthread->td_flags |= TDF_NEEDRESCHED;
847}

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

880
881void
882sched_fork_ksegrp(struct ksegrp *kg, struct ksegrp *child)
883{
884
885 PROC_LOCK_ASSERT(child->kg_proc, MA_OWNED);
886 /* XXX Need something better here */
887
847 CTR2(KTR_ULE, "wakeup kse %p (%d ticks)",
848 td->td_kse, hzticks);
849 td->td_slptime = 0;
850 }
851 setrunqueue(td);
852 if (td->td_priority < curthread->td_priority)
853 curthread->td_flags |= TDF_NEEDRESCHED;
854}

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

887
888void
889sched_fork_ksegrp(struct ksegrp *kg, struct ksegrp *child)
890{
891
892 PROC_LOCK_ASSERT(child->kg_proc, MA_OWNED);
893 /* XXX Need something better here */
894
888#if 1
889 child->kg_slptime = kg->kg_slptime;
890 child->kg_runtime = kg->kg_runtime;
895 child->kg_slptime = kg->kg_slptime;
896 child->kg_runtime = kg->kg_runtime;
891#else
892 if (kg->kg_slptime > kg->kg_runtime) {
893 child->kg_slptime = SCHED_DYN_RANGE;
894 child->kg_runtime = kg->kg_slptime / SCHED_DYN_RANGE;
895 } else {
896 child->kg_runtime = SCHED_DYN_RANGE;
897 child->kg_slptime = kg->kg_runtime / SCHED_DYN_RANGE;
898 }
899#endif
897 kg->kg_runtime += tickincr << 10;
898 sched_interact_update(kg);
900
901 child->kg_user_pri = kg->kg_user_pri;
902 child->kg_nice = kg->kg_nice;
903}
904
905void
906sched_fork_thread(struct thread *td, struct thread *child)
907{

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

951sched_exit_kse(struct kse *ke, struct kse *child)
952{
953 kseq_rem(KSEQ_CPU(child->ke_cpu), child);
954}
955
956void
957sched_exit_ksegrp(struct ksegrp *kg, struct ksegrp *child)
958{
899
900 child->kg_user_pri = kg->kg_user_pri;
901 child->kg_nice = kg->kg_nice;
902}
903
904void
905sched_fork_thread(struct thread *td, struct thread *child)
906{

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

950sched_exit_kse(struct kse *ke, struct kse *child)
951{
952 kseq_rem(KSEQ_CPU(child->ke_cpu), child);
953}
954
955void
956sched_exit_ksegrp(struct ksegrp *kg, struct ksegrp *child)
957{
959 kg->kg_slptime += child->kg_slptime;
958 /* kg->kg_slptime += child->kg_slptime; */
960 kg->kg_runtime += child->kg_runtime;
959 kg->kg_runtime += child->kg_runtime;
961 if ((kg->kg_runtime + kg->kg_slptime) > SCHED_SLP_RUN_MAX) {
962 kg->kg_runtime /= SCHED_SLP_RUN_THROTTLE;
963 kg->kg_slptime /= SCHED_SLP_RUN_THROTTLE;
964 }
960 sched_interact_update(kg);
965}
966
967void
968sched_exit_thread(struct thread *td, struct thread *child)
969{
970}
971
972void

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

1037 td->td_flags |= TDF_NEEDRESCHED;
1038 }
1039#endif
1040 /*
1041 * We used a tick charge it to the ksegrp so that we can compute our
1042 * interactivity.
1043 */
1044 kg->kg_runtime += tickincr << 10;
961}
962
963void
964sched_exit_thread(struct thread *td, struct thread *child)
965{
966}
967
968void

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

1033 td->td_flags |= TDF_NEEDRESCHED;
1034 }
1035#endif
1036 /*
1037 * We used a tick charge it to the ksegrp so that we can compute our
1038 * interactivity.
1039 */
1040 kg->kg_runtime += tickincr << 10;
1041 sched_interact_update(kg);
1045
1046 /*
1047 * We used up one time slice.
1048 */
1049 ke->ke_slice--;
1050#ifdef SMP
1051 kseq->ksq_rslices--;
1052#endif

--- 248 unchanged lines hidden ---
1042
1043 /*
1044 * We used up one time slice.
1045 */
1046 ke->ke_slice--;
1047#ifdef SMP
1048 kseq->ksq_rslices--;
1049#endif

--- 248 unchanged lines hidden ---