aboutsummaryrefslogtreecommitdiffstats
path: root/package/kernel/linux/modules/input.mk
Commit message (Expand)AuthorAgeFilesLines
* kernel: Add of_touchscreen.ko to kmod-input-touchscreen-ads7846Hauke Mehrtens2020-02-281-1/+2
* kernel: fix typos in KernelPackage descriptionSungbo Eo2020-02-081-2/+2
* kernel: fix kmod-input-touchscreen-ads7846 depsStijn Tintel2019-02-251-1/+1
* kernel: add kmod-input-touchscreen-ads7846Stijn Tintel2019-02-241-0/+19
* kernel: fix typo in input-gpio-encoder package titleAvi H. D2016-11-261-1/+1
* kernel/gpio_keys: load module on pre-initJohn Crispin2016-02-261-1/+1
* kernel: remove kmod-acpi-button package, it is already built into the kernelFelix Fietkau2015-11-071-16/+0
* linux: enable kmod-acpi-button for x86_64 (#20080)Jo-Philipp Wich2015-07-141-1/+1
* kernel: add uinput moduleJohn Crispin2015-04-021-0/+18
* kernel: add missing symbols to config and modulesJohn Crispin2015-04-011-1/+1
* kernel: remove useless AddDepends/input abstractionFelix Fietkau2015-03-291-9/+7
* kernel: remove useless AddDepends/hid abstractionFelix Fietkau2015-03-291-1/+1
* build: drop obsolete kernel version dependenciesFelix Fietkau2015-01-241-1/+0
* kernel: add references to openwrt alternative button handlingJohn Crispin2015-01-171-0/+6
* kernel: add keyboard-imx moduleLuka Perkov2013-10-251-1/+19
* kernel: make most modules use AutoProbeJohn Crispin2013-09-171-7/+5
* kernel: be consistent with formatting styleLuka Perkov2013-07-261-10/+10
* kernel: remove gpio_buttonsJonas Gorski2013-07-191-18/+0
* packages: clean up the package folderJohn Crispin2013-06-211-0/+206
ef='#n259'>259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
/* 
 ****************************************************************************
 * (C) 2005 - Grzegorz Milos - Intel Research Cambridge
 ****************************************************************************
 *
 *        File: sched.c
 *      Author: Grzegorz Milos
 *     Changes: Robert Kaiser
 *              
 *        Date: Aug 2005
 * 
 * Environment: Xen Minimal OS
 * Description: simple scheduler for Mini-Os
 *
 * The scheduler is non-preemptive (cooperative), and schedules according 
 * to Round Robin algorithm.
 *
 ****************************************************************************
 * 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 <os.h>
#include <hypervisor.h>
#include <time.h>
#include <mm.h>
#include <types.h>
#include <lib.h>
#include <xmalloc.h>
#include <list.h>
#include <sched.h>
#include <semaphore.h>


#ifdef SCHED_DEBUG
#define DEBUG(_f, _a...) \
    printk("MINI_OS(file=sched.c, line=%d) " _f "\n", __LINE__, ## _a)
#else
#define DEBUG(_f, _a...)    ((void)0)
#endif

struct thread *idle_thread = NULL;
MINIOS_LIST_HEAD(exited_threads);
static int threads_started;

struct thread *main_thread;

void inline print_runqueue(void)
{
    struct minios_list_head *it;
    struct thread *th;
    minios_list_for_each(it, &idle_thread->thread_list)
    {
        th = minios_list_entry(it, struct thread, thread_list);
        printk("   Thread \"%s\", runnable=%d\n", th->name, is_runnable(th));
    }
    printk("\n");
}

void schedule(void)
{
    struct thread *prev, *next, *thread;
    struct minios_list_head *iterator, *next_iterator;
    unsigned long flags;

    prev = current;
    local_irq_save(flags); 

    if (in_callback) {
        printk("Must not call schedule() from a callback\n");
        BUG();
    }
    if (flags) {
        printk("Must not call schedule() with IRQs disabled\n");
        BUG();
    }

    do {
        /* Examine all threads.
           Find a runnable thread, but also wake up expired ones and find the
           time when the next timeout expires, else use 10 seconds. */
        s_time_t now = NOW();
        s_time_t min_wakeup_time = now + SECONDS(10);
        next = NULL;   
        minios_list_for_each_safe(iterator, next_iterator, &idle_thread->thread_list)
        {
            thread = minios_list_entry(iterator, struct thread, thread_list);
            if (!is_runnable(thread) && thread->wakeup_time != 0LL)
            {
                if (thread->wakeup_time <= now)
                    wake(thread);
                else if (thread->wakeup_time < min_wakeup_time)
                    min_wakeup_time = thread->wakeup_time;
            }
            if(is_runnable(thread)) 
            {
                next = thread;
                /* Put this thread on the end of the list */
                minios_list_del(&thread->thread_list);
                minios_list_add_tail(&thread->thread_list, &idle_thread->thread_list);
                break;
            }
        }
        if (next)
            break;
        /* block until the next timeout expires, or for 10 secs, whichever comes first */
        block_domain(min_wakeup_time);
        /* handle pending events if any */
        force_evtchn_callback();
    } while(1);
    local_irq_restore(flags);
    /* Interrupting the switch is equivalent to having the next thread
       inturrupted at the return instruction. And therefore at safe point. */
    if(prev != next) switch_threads(prev, next);

    minios_list_for_each_safe(iterator, next_iterator, &exited_threads)
    {
        thread = minios_list_entry(iterator, struct thread, thread_list);
        if(thread != prev)
        {
            minios_list_del(&thread->thread_list);
            free_pages(thread->stack, STACK_SIZE_PAGE_ORDER);
            xfree(thread);
        }
    }
}

struct thread* create_thread(char *name, void (*function)(void *), void *data)
{
    struct thread *thread;
    unsigned long flags;
    /* Call architecture specific setup. */
    thread = arch_create_thread(name, function, data);
    /* Not runable, not exited, not sleeping */
    thread->flags = 0;
    thread->wakeup_time = 0LL;
#ifdef HAVE_LIBC
    _REENT_INIT_PTR((&thread->reent))
#endif
    set_runnable(thread);
    local_irq_save(flags);
    if(idle_thread != NULL) {
        minios_list_add_tail(&thread->thread_list, &idle_thread->thread_list); 
    } else if(function != idle_thread_fn)
    {
        printk("BUG: Not allowed to create thread before initialising scheduler.\n");
        BUG();
    }
    local_irq_restore(flags);
    return thread;
}

#ifdef HAVE_LIBC
static struct _reent callback_reent;
struct _reent *__getreent(void)
{
    struct _reent *_reent;

    if (!threads_started)
	_reent = _impure_ptr;
    else if (in_callback)
	_reent = &callback_reent;
    else
	_reent = &get_current()->reent;

#ifndef NDEBUG
#if defined(__x86_64__) || defined(__x86__)
    {
#ifdef __x86_64__
	register unsigned long sp asm ("rsp");
#else
	register unsigned long sp asm ("esp");
#endif
	if ((sp & (STACK_SIZE-1)) < STACK_SIZE / 16) {
	    static int overflowing;
	    if (!overflowing) {
		overflowing = 1;
		printk("stack overflow\n");
		BUG();
	    }
	}
    }
#endif
#endif
    return _reent;
}
#endif

void exit_thread(void)
{
    unsigned long flags;
    struct thread *thread = current;
    printk("Thread \"%s\" exited.\n", thread->name);
    local_irq_save(flags);
    /* Remove from the thread list */
    minios_list_del(&thread->thread_list);
    clear_runnable(thread);
    /* Put onto exited list */
    minios_list_add(&thread->thread_list, &exited_threads);
    local_irq_restore(flags);
    /* Schedule will free the resources */
    while(1)
    {
        schedule();
        printk("schedule() returned!  Trying again\n");
    }
}

void block(struct thread *thread)
{
    thread->wakeup_time = 0LL;
    clear_runnable(thread);
}

void msleep(u32 millisecs)
{
    struct thread *thread = get_current();
    thread->wakeup_time = NOW()  + MILLISECS(millisecs);
    clear_runnable(thread);
    schedule();
}

void wake(struct thread *thread)
{
    thread->wakeup_time = 0LL;
    set_runnable(thread);
}

void idle_thread_fn(void *unused)
{
    threads_started = 1;
    while (1) {
        block(current);
        schedule();
    }
}

DECLARE_MUTEX(mutex);

void th_f1(void *data)
{
    struct timeval tv1, tv2;

    for(;;)
    {
        down(&mutex);
        printk("Thread \"%s\" got semaphore, runnable %d\n", current->name, is_runnable(current));
        schedule();
        printk("Thread \"%s\" releases the semaphore\n", current->name);
        up(&mutex);
        
        
        gettimeofday(&tv1, NULL);
        for(;;)
        {
            gettimeofday(&tv2, NULL);
            if(tv2.tv_sec - tv1.tv_sec > 2) break;
        }
                
        
        schedule(); 
    }
}

void th_f2(void *data)
{
    for(;;)
    {
        printk("Thread OTHER executing, data 0x%lx\n", data);
        schedule();
    }
}



void init_sched(void)
{
    printk("Initialising scheduler\n");

#ifdef HAVE_LIBC
    _REENT_INIT_PTR((&callback_reent))
#endif
    idle_thread = create_thread("Idle", idle_thread_fn, NULL);
    MINIOS_INIT_LIST_HEAD(&idle_thread->thread_list);
}