Thanks for the quick reply.

On Wed, Mar 28, 2018 at 6:19 AM, Richard Weinberger <rich...@nod.at> wrote:
> Am Mittwoch, 28. März 2018, 15:11:29 CEST schrieb Geert Uytterhoeven:
>> On Wed, Mar 28, 2018 at 12:28 PM, Joel Fernandes <agnel.j...@gmail.com>
> wrote:
>> >         while(release_now == 0);
>>
>> while (release_now == 0)
>>         cpu_relax();
>
> Not sure whether a cpu_relax() fixes the problem.
> I guess the root of the problem is that UML is UP and non-preemptive.
> Therefore the loop is never interrupted.
> To verify I asked for the full source.
>

cpu_relax actually worked!

Any thoughts on why it helps? Even if its non-preemptive, I did
receive the timer interrupt, so I expected the variable to be set.

Module is attached.

Thanks,
-Joel
/*
 * This module emits "Hello, world" on printk when loaded.
 *
 * It is designed to be used for basic evaluation of the module loading
 * subsystem (for example when validating module signing/verification). It
 * lacks any extra dependencies, and will not normally be loaded by the
 * system unless explicitly requested by name.
 */

#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

#include <linux/init.h>
#include <linux/module.h>
#include <linux/printk.h>
#include <linux/ratelimit.h>
#include <linux/delay.h>
#include <linux/sched.h>

struct bigstr {
	spinlock_t biglock;
};

struct bigstr *il;
struct hrtimer bigtimer;
int release_now;

static enum hrtimer_restart bigtimer_handle(struct hrtimer *timer)
{
	printk(KERN_ERR "timer fired 2\n");
	spin_lock(&il->biglock);
	spin_unlock(&il->biglock);

	release_now = 1;

	return HRTIMER_NORESTART;
}

void init_bigstr(struct bigstr *b)
{
	spin_lock_init(&b->biglock);
}

static int __init test_module_init(void)
{
	struct bigstr b1, b2;
	struct hrtimer *timer;

	release_now = 0;

	init_bigstr(&b1);
	init_bigstr(&b2);

	timer = &bigtimer;
	timer->debug = 1;

	hrtimer_init(timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
	timer->function = bigtimer_handle;

	il = &b2;
	spin_lock(&b1.biglock);

	printk(KERN_ERR "Starting timer\n");
	hrtimer_start(timer, ns_to_ktime(50000ULL),
		      HRTIMER_MODE_REL_PINNED);

	while(release_now == 0)
		cpu_relax();

	spin_unlock(&b1.biglock);
	return -1;
}

module_init(test_module_init);

static void __exit test_module_exit(void)
{
}

module_exit(test_module_exit);

MODULE_AUTHOR("Joel Fernandes <agnel.j...@gmail.com>");
MODULE_LICENSE("GPL");
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

Reply via email to