<commit_before>/*
 *    Precise Delay Loops for S390
 *
 *    Copyright IBM Corp. 1999,2008
 *    Author(s): <NAME> <<EMAIL>>,
 *		 <NAME> <<EMAIL>>,
 */

#include <linux/sched.h>
#include <linux/delay.h>
#include <linux/timex.h>
#include <linux/module.h>
#include <linux/irqflags.h>
#include <linux/interrupt.h>

void __delay(unsigned long loops)
{
        /*
         * To end the bloody studid and useless discussion about the
         * BogoMips number I took the liberty to define the __delay
         * function in a way that that resulting BogoMips number will
         * yield the megahertz number of the cpu. The important function
         * is udelay and that is done using the tod clock. -- martin.
         */
	asm volatile("0: brct %0,0b" : : "d" ((loops/2) + 1));
}

static void __udelay_disabled(unsigned long usecs)
{
	unsigned long mask, cr0, cr0_saved;
	u64 clock_saved;

	clock_saved = local_tick_disable();
	set_clock_comparator(get_clock() + ((u64) usecs << 12));
	__ctl_store(cr0_saved, 0, 0);
	cr0 = (cr0_saved & 0xffff00e0) | 0x00000800;
	__ctl_load(cr0 , 0, 0);
	mask = psw_kernel_bits | PSW_MASK_WAIT | PSW_MASK_EXT;
	lockdep_off();
	trace_hardirqs_on();
	__load_psw_mask(mask);
	local_irq_disable();
	lockdep_on();
	__ctl_load(cr0_saved, 0, 0);
	local_tick_enable(clock_saved);
	set_clock_comparator(S390_lowcore.clock_comparator);
}

static void __udelay_enabled(unsigned long usecs)
{
	unsigned long mask;
	u64 end, time;

	mask = psw_kernel_bits | PSW_MASK_WAIT | PSW_MASK_EXT | PSW_MASK_IO;
	end = get_clock() + ((u64) usecs << 12);
	do {
		time = end < S390_lowcore.clock_comparator ?
			end : S390_lowcore.clock_comparator;
		set_clock_comparator(time);
		trace_hardirqs_on();
		__load_psw_mask(mask);
		local_irq_disable();
	} while (get_clock() < end);
	set_clock_comparator(S390_lowcore.clock_comparator);
}

/*
 * Waits for 'usecs' microseconds using the TOD clock comparator.
 */
void __udelay(unsigned long usecs)
{
	unsigned long flags;

	preempt_disable();
	local_irq_save(flags);
	if (in_irq()) {
		__udelay_disabled(usecs);
		goto out;<commit_msg>[S390] Fix enabled udelay for short delays.<commit_after>/*
 *    Precise Delay Loops for S390
 *
 *    Copyright IBM Corp. 1999,2008
 *    Author(s): <NAME> <<EMAIL>>,
 *		 <NAME> <<EMAIL>>,
 */

#include <linux/sched.h>
#include <linux/delay.h>
#include <linux/timex.h>
#include <linux/module.h>
#include <linux/irqflags.h>
#include <linux/interrupt.h>

void __delay(unsigned long loops)
{
        /*
         * To end the bloody studid and useless discussion about the
         * BogoMips number I took the liberty to define the __delay
         * function in a way that that resulting BogoMips number will
         * yield the megahertz number of the cpu. The important function
         * is udelay and that is done using the tod clock. -- martin.
         */
	asm volatile("0: brct %0,0b" : : "d" ((loops/2) + 1));
}

static void __udelay_disabled(unsigned long usecs)
{
	unsigned long mask, cr0, cr0_saved;
	u64 clock_saved;

	clock_saved = local_tick_disable();
	set_clock_comparator(get_clock() + ((u64) usecs << 12));
	__ctl_store(cr0_saved, 0, 0);
	cr0 = (cr0_saved & 0xffff00e0) | 0x00000800;
	__ctl_load(cr0 , 0, 0);
	mask = psw_kernel_bits | PSW_MASK_WAIT | PSW_MASK_EXT;
	lockdep_off();
	trace_hardirqs_on();
	__load_psw_mask(mask);
	local_irq_disable();
	lockdep_on();
	__ctl_load(cr0_saved, 0, 0);
	local_tick_enable(clock_saved);
	set_clock_comparator(S390_lowcore.clock_comparator);
}

static void __udelay_enabled(unsigned long usecs)
{
	unsigned long mask;
	u64 clock_saved;
	u64 end;

	mask = psw_kernel_bits | PSW_MASK_WAIT | PSW_MASK_EXT | PSW_MASK_IO;
	end = get_clock() + ((u64) usecs << 12);
	do {
		clock_saved = 0;
		if (end < S390_lowcore.clock_comparator) {
			clock_saved = local_tick_disable();
			set_clock_comparator(end);
		}
		trace_hardirqs_on();
		__load_psw_mask(mask);
		local_irq_disable();
		if (clock_saved)
			local_tick_enable(clock_saved);
	} while (get_clock() < end);
	set_clock_comparator(S390_lowcore.clock_comparator);
}

/*
 * Waits for 'usecs' microseconds using the TOD clock comparator.
 */
void __udelay(unsigned long usecs)
{
	unsigned long flags;

	preempt_disable();
	local_irq_save(flags);
	if (in_irq()) {
		__udelay_disabled(usecs);
		goto out;
{'fraction_non_alphanumeric': 0.11889250814332247, 'fraction_numerical': 0.03140995812005584, 'mean_word_length': 4.160864345738295, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7018657', 'n_tokens_mistral': 1731, 'n_tokens_neox': 1635, 'n_words': 389}