Attached below an example code demonstration:

-----------------------
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kthread.h>
#include <linux/delay.h>

struct task_struct *kthread;

int thread(void *args)
{
    while (!kthread_should_stop()) {
        mdelay(5000);
        printk(KERN_INFO "Hello!\n");
        schedule(); /* To avoid hanging */
    }

    kthread = NULL;
    do_exit(0);
}

static int __init hello_init(void)
{
    kthread = kthread_create(thread, NULL, "test_mdelay");
    if (IS_ERR(kthread))
        printk(KERN_INFO "Error creating kthread\n");
    else
        wake_up_process(kthread);
    return 0;
}

static void __exit hello_exit(void)
{
    if (kthread)
        kthread_stop(kthread);
}

module_init(hello_init);
module_exit(hello_exit);

MODULE_LICENSE("Dual BSD/GPL");

-----------------------


David Ramirez wrote:
> I've checked the wrong source version, mdelay() is implemented as:
>
> n = (loops_per_jiffy * HZ * usecs) / MILLION;
> for(i=0;i<n;i++)
>    __asm__ __volatile__("rep;nop": : :"memory");
>
> Similar as it is in x86. But in UML it doesn't work for me.
>
>
> David Ramirez wrote:
>> Hi all,
>>
>> Recently, I decided to use UML to develope my modules. My module 
>> calls mdelay() macro that is implemented in UML as:
>>
>> n = (loops_per_jiffy * HZ * usecs) / MILLION;
>> for(i=0;i<n;i++)
>>    do ; while(0);
>>
>>
>> mdelay() worked perfectly in x86 but in UML it doesnt seem to sleep.
>>
>> I've checked loop values:
>>
>> loops_per_jiffy: 27918336
>> HZ: 100
>> MILLION: 1000000
>>
>> My system is:
>> linux 2.6.32-r5
>> gcc version 4.3.4 (Debian 4.3.4-2)
>>
>> Can it be a compiler optimization?
>>
>> Thanks in advance,
>>   David
>>
>>
>>
>
>


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
User-mode-linux-user mailing list
User-mode-linux-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-user

Reply via email to