Welcome to mirror list, hosted at ThFree Co, Russian Federation.

kernel_sched.c « sparc_leon « libgloss - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9d625ce9eb370933b3fb62651e77d5c8bea0a739 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
 * Copyright (c) 2011 Aeroflex Gaisler
 *
 * BSD license:
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */


#include <asm-leon/contextswitch.h>
#include <asm-leon/leonbare_kernel.h>
#include <asm-leon/leonbare_debug.h>
#include <asm-leon/stack.h>
#include <asm-leon/leonstack.h>
#include <asm-leon/irq.h>

unsigned int
reschedule ()
{
  leonbare_sched_update ();
  return leonbare_sched ();
}

unsigned int
leonbare_sched ()
{
  unsigned int ret = 0;
  volatile leonbare_thread_t old = LEONBARE_KR_CURRENT, new =
    LEONBARE_KR_NEXT;
  LBDEBUG_FNCALL;
  LBDEBUG_HEADER_PRINTF (LBDEBUG_SCHED_NR, "switch %s[%x]->%s[%x]\n",
			 LEONBARE_TH_NAME_DBG (old), old,
			 LEONBARE_TH_NAME_DBG (new), new);

  LBPASSERT ((old != new),
	     "leonbare_sched should only be called with reschedule work to do",
	     0);

  LEONBARE_KR_CURRENT = new;

  /* to be able to programm symetrically on kernel level each thread
     saves its spinlock on mutexes and kernel and irq flags in its
     own save region. On a kernel switch they are released until the
     thread is reawakened. Then the locks will be reaquired (and finally
     released when the codeblock exits). The locking can be recursive. */
  if (old->th_prot.krp_k_depth)
    {
      LEONBARE_SMP_SPINLOCK_RELEASE (LEONBARE_KR_LOCK);
    }
  if (old->th_prot.krp_m_depth)
    {
      LEONBARE_SMP_SPINLOCK_RELEASE (old->th_prot.krp_m);
    }

  ret = _leonbare_kernel_switchto (old, new);
  optbarrier ();

  if (new->th_prot.krp_m_depth)
    {
      LEONBARE_SMP_SPINLOCK_AQUIRE (new->th_prot.krp_m);
    }
  if (old->th_prot.krp_k_depth)
    {
      LEONBARE_SMP_SPINLOCK_AQUIRE (LEONBARE_KR_LOCK);
    }

  return ret;
}