aboutsummaryrefslogtreecommitdiffstats
path: root/package/kernel/linux/modules/iio.mk
diff options
context:
space:
mode:
authorBirger Koblitz <git@birger-koblitz.de>2022-01-06 20:27:01 +0100
committerDaniel Golle <daniel@makrotopia.org>2022-02-17 15:21:47 +0000
commit775d903216a08c2a8009863d2f9c33f62657ba94 (patch)
treeb16ff251bb9024bbdfa098d77277556c48952546 /package/kernel/linux/modules/iio.mk
parent0536c582e673aa292377f4b8cb11002238a39d32 (diff)
downloadupstream-775d903216a08c2a8009863d2f9c33f62657ba94.tar.gz
upstream-775d903216a08c2a8009863d2f9c33f62657ba94.tar.bz2
upstream-775d903216a08c2a8009863d2f9c33f62657ba94.zip
realtek: Replace the RTL9300 generic timer with a CEVT timer
The RTL9300 has a broken R4K MIPS timer interrupt, however, the R4K clocksource works. We replace the RTL9300 timer with a Clock Event Timer (CEVT), which is VSMP aware and can be instantiated as part of brining a VSMTP cpu up instead of the R4K CEVT source. For this we place the RTL9300 CEVT timer in arch/mips/kernel together with other MIPS CEVT timers, initialize the SoC IRQs from a modified smp-mt.c and instantiate each timer as part of the MIPS time setup in arch/mips/include/asm/time.h instead of the R4K CEVT, similarly as is done by other MIPS CEVT timers. Signed-off-by: Birger Koblitz <git@birger-koblitz.de>
Diffstat (limited to 'package/kernel/linux/modules/iio.mk')
0 files changed, 0 insertions, 0 deletions
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 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 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767
/* -*-  Mode:C; c-basic-offset:4; tab-width:4 -*-
 ****************************************************************************
 * (C) 2002-2003 - Rolf Neugebauer - Intel Research Cambridge
 * (C) 2002-2003 University of Cambridge
 * (C) 2004      - Mark Williamson - Intel Research Cambridge
 ****************************************************************************
 *
 *        File: common/schedule.c
 *      Author: Rolf Neugebauer & Keir Fraser
 *              Updated for generic API by Mark Williamson
 * 
 * Description: Generic CPU scheduling code
 *              implements support functionality for the Xen scheduler API.
 *
 */

#include <xen/config.h>
#include <xen/init.h>
#include <xen/lib.h>
#include <xen/sched.h>
#include <xen/delay.h>
#include <xen/event.h>
#include <xen/time.h>
#include <xen/ac_timer.h>
#include <xen/interrupt.h>
#include <xen/timer.h>
#include <xen/perfc.h>
#include <xen/sched-if.h>
#include <hypervisor-ifs/sched_ctl.h>
#include <xen/trace.h>

/*#define WAKEUP_HISTO*/
/*#define BLOCKTIME_HISTO*/

#if defined(WAKEUP_HISTO)
#define BUCKETS 31
#elif defined(BLOCKTIME_HISTO)
#define BUCKETS 200
#endif

#define TIME_SLOP      (s32)MICROSECS(50)     /* allow time to slip a bit */

/*
 * TODO MAW pull trace-related #defines out of here and into an auto-generated
 * header file later on!
 */
#define TRC_SCHED_DOM_ADD             0x00010000
#define TRC_SCHED_DOM_REM             0x00010001
#define TRC_SCHED_WAKE                0x00010002
#define TRC_SCHED_BLOCK               0x00010003
#define TRC_SCHED_YIELD               0x00010004
#define TRC_SCHED_SET_TIMER           0x00010005
#define TRC_SCHED_CTL                 0x00010006
#define TRC_SCHED_ADJDOM              0x00010007
#define TRC_SCHED_RESCHED             0x00010008
#define TRC_SCHED_SWITCH              0x00010009
#define TRC_SCHED_S_TIMER_FN          0x0001000A
#define TRC_SCHED_T_TIMER_FN          0x0001000B
#define TRC_SCHED_DOM_TIMER_FN        0x0001000C
#define TRC_SCHED_FALLBACK_TIMER_FN   0x0001000D

#define _HIGH32(_x) (_x >> 32)
#define _LOW32(_x)  ((u32)_x )

/* Various timer handlers. */
static void s_timer_fn(unsigned long unused);
static void t_timer_fn(unsigned long unused);
static void dom_timer_fn(unsigned long data);
static void fallback_timer_fn(unsigned long unused);

/* This is global for now so that private implementations can reach it */
schedule_data_t schedule_data[NR_CPUS];

/*
 * TODO: It would be nice if the schedulers array could get populated
 * automagically without having to hack the code in here.
 */
extern struct scheduler sched_bvt_def, sched_rrobin_def, sched_atropos_def;
static struct scheduler *schedulers[] = { &sched_bvt_def,
                                          &sched_rrobin_def,
                                          &sched_atropos_def,
                                          NULL};

/* Operations for the current scheduler. */
static struct scheduler ops;

#define SCHED_OP(fn, ...)                                 \
         (( ops.fn != NULL ) ? ops.fn( __VA_ARGS__ )      \
          : (typeof(ops.fn(__VA_ARGS__)))0 )

spinlock_t schedule_lock[NR_CPUS] __cacheline_aligned;

/* Per-CPU periodic timer sends an event to the currently-executing domain. */
static struct ac_timer t_timer[NR_CPUS]; 

/*
 * Per-CPU timer which ensures that even guests with very long quantums get
 * their time-of-day state updated often enough to avoid wrapping.
 */
static struct ac_timer fallback_timer[NR_CPUS];

extern kmem_cache_t *task_struct_cachep;

void free_task_struct(struct task_struct *p)
{
    SCHED_OP(free_task, p);
    kmem_cache_free(task_struct_cachep, p);
}

/**
 * alloc_task_struct - allocate a new task_struct and sched private structures
 */
struct task_struct *alloc_task_struct(void)
{
    struct task_struct *p;

    if ( (p = kmem_cache_alloc(task_struct_cachep,GFP_KERNEL)) == NULL )
        return NULL;
    
    memset(p, 0, sizeof(*p));

    if ( SCHED_OP(alloc_task, p) < 0 )
    {
        kmem_cache_free(task_struct_cachep,p);
        return NULL;
    }

    return p;
}

/*
 * Add and remove a domain
 */
void sched_add_domain(struct task_struct *p) 
{
    p->state = TASK_STOPPED;

    if ( p->domain != IDLE_DOMAIN_ID )
    {
        /* Initialise the per-domain timer. */
        init_ac_timer(&p->timer);
        p->timer.cpu      =  p->processor;
        p->timer.data     = (unsigned long)p;
        p->timer.function = &dom_timer_fn;
    }
    else
    {
        schedule_data[p->processor].idle = p;
    }

    SCHED_OP(add_task, p);

    TRACE_3D(TRC_SCHED_DOM_ADD, _HIGH32(p->domain), _LOW32(p->domain), p);
}

int sched_rem_domain(struct task_struct *p) 
{
    int x, y = p->state;
    do {
        if ( (x = y) == TASK_DYING ) return 0;
    } while ( (y = cmpxchg(&p->state, x, TASK_DYING)) != x );

    rem_ac_timer(&p->timer);

    SCHED_OP(rem_task, p);

    TRACE_3D(TRC_SCHED_DOM_REM, _HIGH32(p->domain), _LOW32(p->domain), p);

    return 1;
}

void init_idle_task(void)
{
    unsigned long flags;
    struct task_struct *p = current;

    if ( SCHED_OP(alloc_task, p) < 0)
        panic("Failed to allocate scheduler private data for idle task");
    SCHED_OP(add_task, p);

    spin_lock_irqsave(&schedule_lock[p->processor], flags);
    p->has_cpu = 1;
    p->state = TASK_RUNNING;
    if ( !__task_on_runqueue(p) )
        __add_to_runqueue_head(p);
    spin_unlock_irqrestore(&schedule_lock[p->processor], flags);
}

void __wake_up(struct task_struct *p)
{
    TRACE_3D(TRC_SCHED_WAKE, _HIGH32(p->domain), _LOW32(p->domain), p);

    ASSERT(p->state != TASK_DYING);

    if ( unlikely(__task_on_runqueue(p)) )        
        return;

    p->state = TASK_RUNNING;

    SCHED_OP(wake_up, p);

#ifdef WAKEUP_HISTO
    p->wokenup = NOW();
#endif
}


void wake_up(struct task_struct *p)
{
    unsigned long flags;
    spin_lock_irqsave(&schedule_lock[p->processor], flags);
    __wake_up(p);
    spin_unlock_irqrestore(&schedule_lock[p->processor], flags);
}

/* 
 * Block the currently-executing domain until a pertinent event occurs.
 */
static long do_block(void)
{
    ASSERT(current->domain != IDLE_DOMAIN_ID);
    current->shared_info->vcpu_data[0].evtchn_upcall_mask = 0;
    current->state = TASK_INTERRUPTIBLE;
    TRACE_2D(TRC_SCHED_BLOCK, current->domain, current);
    __enter_scheduler();
    return 0;
}

/*
 * Voluntarily yield the processor for this allocation.
 */
static long do_yield(void)
{
    TRACE_2D(TRC_SCHED_YIELD, current->domain, current);
    __enter_scheduler();
    return 0;
}


/*
 * Demultiplex scheduler-related hypercalls.
 */
long do_sched_op(unsigned long op)
{
    long ret = 0;

    switch( op ) 
    {

    case SCHEDOP_yield:
    {
        ret = do_yield();
        break;
    }

    case SCHEDOP_block:
    {
        ret = do_block();
        break;
    }

    case SCHEDOP_exit:
    {
        DPRINTK("DOM%llu killed itself!\n", current->domain);
        DPRINTK(" EIP == %08lx\n", get_execution_context()->eip);
        kill_domain();
        break;
    }

    case SCHEDOP_stop:
    {
        DPRINTK("DOM%llu stopped itself!\n", current->domain);
        DPRINTK(" EIP == %08lx\n", get_execution_context()->eip);
        stop_domain();
        break;
    }

    default:
        ret = -ENOSYS;
    }

    return ret;
}


/*
 * sched_pause_sync - synchronously pause a domain's execution 
 * XXXX This is horibly broken -- here just as a place holder at present,
 *                                do not use.
 */
void sched_pause_sync(struct task_struct *p)
{
    unsigned long flags;
    int cpu = p->processor;

    spin_lock_irqsave(&schedule_lock[cpu], flags);

    /* If not the current task, we can remove it from scheduling now. */
    if ( schedule_data[cpu].curr != p )
        SCHED_OP(pause, p);

    p->state = TASK_PAUSED;
    
    spin_unlock_irqrestore(&schedule_lock[cpu], flags);

    /* Spin until domain is descheduled by its local scheduler. */
    while ( schedule_data[cpu].curr == p )
    {
        send_hyp_event(p, _HYP_EVENT_NEED_RESCHED );
        do_yield();
    }
        
    /* The domain will not be scheduled again until we do a wake_up(). */
}

/* Per-domain one-shot-timer hypercall. */
long do_set_timer_op(unsigned long timeout_hi, unsigned long timeout_lo)
{
    struct task_struct *p = current;

    rem_ac_timer(&p->timer);
    
    if ( (timeout_hi != 0) || (timeout_lo != 0) )
    {
        p->timer.expires = ((s_time_t)timeout_hi<<32) | ((s_time_t)timeout_lo);
        add_ac_timer(&p->timer);
    }

    TRACE_5D(TRC_SCHED_SET_TIMER, _HIGH32(p->domain), _LOW32(p->domain),
             p, timeout_hi, timeout_lo);

    return 0;
}

/** sched_id - fetch ID of current scheduler */
int sched_id()
{
    return ops.sched_id;
}

long sched_ctl(struct sched_ctl_cmd *cmd)
{
    TRACE_0D(TRC_SCHED_CTL);

    if ( cmd->sched_id != ops.sched_id )
        return -EINVAL;

    return SCHED_OP(control, cmd);
}


/* Adjust scheduling parameter for a given domain. */
long sched_adjdom(struct sched_adjdom_cmd *cmd)
{
    struct task_struct *p;    
    
    if ( cmd->sched_id != ops.sched_id )
        return -EINVAL;

    if ( cmd->direction != SCHED_INFO_PUT && cmd->direction != SCHED_INFO_GET )
        return -EINVAL;

    p = find_domain_by_id(cmd->domain);

    if( p == NULL )
        return -ESRCH;

    TRACE_2D(TRC_SCHED_ADJDOM, _HIGH32(p->domain), _LOW32(p->domain));

    SCHED_OP(adjdom, p, cmd);

    put_task_struct(p); 
    return 0;
}

/*
 * cause a run through the scheduler when appropriate
 * Appropriate is:
 * - current task is idle task
 * - the current task already ran for it's context switch allowance
 * Otherwise we do a run through the scheduler after the current tasks 
 * context switch allowance is over.
 */
unsigned long __reschedule(struct task_struct *p)
{
       int cpu = p->processor;
    struct task_struct *curr;
    s_time_t now, min_time;

    TRACE_3D(TRC_SCHED_RESCHED, _HIGH32(p->domain), _LOW32(p->domain), p);

    if ( unlikely(p->has_cpu || !__task_on_runqueue(p)) )
        return 0;

    now = NOW();
    curr = schedule_data[cpu].curr;
    /* domain should run at least for ctx_allow */
    min_time = curr->lastschd + curr->min_slice;

    if ( is_idle_task(curr) || (min_time <= now) )
    {
        set_bit(_HYP_EVENT_NEED_RESCHED, &curr->hyp_events);
        return (1 << p->processor);
    }

    /* current hasn't been running for long enough -> reprogram timer.
     * but don't bother if timer would go off soon anyway */
    if ( schedule_data[cpu].s_timer.expires > min_time + TIME_SLOP )
        mod_ac_timer(&schedule_data[cpu].s_timer, min_time);

    return SCHED_OP(reschedule, p);
}

void reschedule(struct task_struct *p)
{
    unsigned long flags, cpu_mask;

    spin_lock_irqsave(&schedule_lock[p->processor], flags);
    cpu_mask = __reschedule(p);

    spin_unlock_irqrestore(&schedule_lock[p->processor], flags);

#ifdef CONFIG_SMP
    cpu_mask &= ~(1 << smp_processor_id());
    if ( cpu_mask != 0 )
        smp_send_event_check_mask(cpu_mask);
#endif
}

/* 
 * The main function
 * - deschedule the current domain (scheduler independent).
 * - pick a new domain (scheduler dependent).
 */
asmlinkage void __enter_scheduler(void)
{
    struct task_struct *prev = current, *next = NULL;
    int                 cpu = prev->processor;
    s_time_t            now;
    task_slice_t        next_slice;
    s32                 r_time;     /* time for new dom to run */

    perfc_incrc(sched_run);

    clear_bit(_HYP_EVENT_NEED_RESCHED, &prev->hyp_events);

    spin_lock_irq(&schedule_lock[cpu]);

    now = NOW();

    rem_ac_timer(&schedule_data[cpu].s_timer);
    
    ASSERT(!in_interrupt());
    ASSERT(__task_on_runqueue(prev));
    ASSERT(prev->state != TASK_UNINTERRUPTIBLE);

    if ( prev->state == TASK_INTERRUPTIBLE )
    {
        /* this check is needed to avoid a race condition */
        if ( signal_pending(prev) )
            prev->state = TASK_RUNNING;
        else
            SCHED_OP(do_block, prev);
    }

    prev->cpu_time += now - prev->lastschd;

    /* get policy-specific decision on scheduling... */
    next_slice = ops.do_schedule(now);

    r_time = next_slice.time;
    next = next_slice.task;

    prev->has_cpu = 0;
    next->has_cpu = 1;

    schedule_data[cpu].curr = next;

    next->lastschd = now;

    /* reprogramm the timer */
    schedule_data[cpu].s_timer.expires  = now + r_time;
    add_ac_timer(&schedule_data[cpu].s_timer);

    spin_unlock_irq(&schedule_lock[cpu]);

    /* Ensure that the domain has an up-to-date time base. */
    if ( !is_idle_task(next) )
        update_dom_time(next->shared_info);

    if ( unlikely(prev == next) )
        return;
    
    perfc_incrc(sched_ctx);

#if defined(WAKEUP_HISTO)
    if ( !is_idle_task(next) && next->wokenup ) {
        ulong diff = (ulong)(now - next->wokenup);
        diff /= (ulong)MILLISECS(1);
        if (diff <= BUCKETS-2)  schedule_data[cpu].hist[diff]++;
        else                    schedule_data[cpu].hist[BUCKETS-1]++;
    }
    next->wokenup = (s_time_t)0;
#elif defined(BLOCKTIME_HISTO)
    prev->lastdeschd = now;
    if ( !is_idle_task(next) )
    {
        ulong diff = (ulong)((now - next->lastdeschd) / MILLISECS(10));
        if (diff <= BUCKETS-2)  schedule_data[cpu].hist[diff]++;
        else                    schedule_data[cpu].hist[BUCKETS-1]++;
    }
#endif

    TRACE_2D(TRC_SCHED_SWITCH, next->domain, next);

    switch_to(prev, next);
    
    if ( unlikely(prev->state == TASK_DYING) ) 
        put_task_struct(prev);

    /* Mark a timer event for the newly-scheduled domain. */
    if ( !is_idle_task(next) )
        evtchn_set_pending(next, VIRQ_TIMER);
    
    schedule_tail(next);

    BUG();
}

/* No locking needed -- pointer comparison is safe :-) */
int idle_cpu(int cpu)
{
    struct task_struct *p = schedule_data[cpu].curr;
    return p == idle_task[cpu];
}


/****************************************************************************
 * Timers: the scheduler utilises a number of timers
 * - s_timer: per CPU timer for preemption and scheduling decisions
 * - t_timer: per CPU periodic timer to send timer interrupt to current dom
 * - dom_timer: per domain timer to specifiy timeout values
 * - fallback_timer: safeguard to ensure time is up to date
 ****************************************************************************/

/* The scheduler timer: force a run through the scheduler*/
static void s_timer_fn(unsigned long unused)
{
    TRACE_0D(TRC_SCHED_S_TIMER_FN);
    set_bit(_HYP_EVENT_NEED_RESCHED, &current->hyp_events);
    perfc_incrc(sched_irq);
}

/* Periodic tick timer: send timer event to current domain*/
static void t_timer_fn(unsigned long unused)
{
    struct task_struct *p = current;

    TRACE_0D(TRC_SCHED_T_TIMER_FN);

    if ( !is_idle_task(p) )
        send_guest_virq(p, VIRQ_TIMER);

    t_timer[p->processor].expires = NOW() + MILLISECS(10);
    add_ac_timer(&t_timer[p->processor]);
}

/* Domain timer function, sends a virtual timer interrupt to domain */
static void dom_timer_fn(unsigned long data)
{
    struct task_struct *p = (struct task_struct *)data;
    TRACE_0D(TRC_SCHED_DOM_TIMER_FN);
    send_guest_virq(p, VIRQ_TIMER);
}


/* Fallback timer to ensure guests get time updated 'often enough'. */
static void fallback_timer_fn(unsigned long unused)
{
    struct task_struct *p = current;

    TRACE_0D(TRC_SCHED_FALLBACK_TIMER_FN);

    if ( !is_idle_task(p) )
        update_dom_time(p->shared_info);

    fallback_timer[p->processor].expires = NOW() + MILLISECS(500);
    add_ac_timer(&fallback_timer[p->processor]);
}

/* Initialise the data structures. */
void __init scheduler_init(void)
{
    int i;

    printk("Initialising schedulers\n");

    for ( i = 0; i < NR_CPUS; i++ )
    {
        INIT_LIST_HEAD(&schedule_data[i].runqueue);
        spin_lock_init(&schedule_lock[i]);
        schedule_data[i].curr = &idle0_task;
        
        init_ac_timer(&schedule_data[i].s_timer);
        schedule_data[i].s_timer.cpu      = i;
        schedule_data[i].s_timer.data     = 2;
        schedule_data[i].s_timer.function = &s_timer_fn;

        init_ac_timer(&t_timer[i]);
        t_timer[i].cpu      = i;
        t_timer[i].data     = 3;
        t_timer[i].function = &t_timer_fn;

        init_ac_timer(&fallback_timer[i]);
        fallback_timer[i].cpu      = i;
        fallback_timer[i].data     = 4;
        fallback_timer[i].function = &fallback_timer_fn;
    }

    schedule_data[0].idle = &idle0_task;

    extern char opt_sched[];

    for ( i = 0; schedulers[i] != NULL; i++ )