Ejemplo n.º 1
0
static int start_bw_hwmon(struct bw_hwmon *hw, unsigned long mbps)
{
	struct bwmon *m = to_bwmon(hw);
	u32 limit;
	int ret;

	ret = request_threaded_irq(m->irq, NULL, bwmon_intr_handler,
				  IRQF_ONESHOT | IRQF_SHARED,
				  dev_name(m->dev), m);
	if (ret) {
		dev_err(m->dev, "Unable to register interrupt handler! (%d)\n",
				ret);
		return ret;
	}

	mon_disable(m);

	limit = mbps_to_bytes(mbps, hw->df->profile->polling_ms, 0);
	mon_set_limit(m, limit);

	mon_clear(m);
	mon_irq_clear(m);
	mon_irq_enable(m);
	mon_enable(m);

	return 0;
}
Ejemplo n.º 2
0
void mpoly_randtest(mpoly_t rop, flint_rand_t state, long d, long N, 
                    const ctx_t ctx)
{
    long i, n = rop->n;

    mpoly_zero(rop, ctx);

    for (i = 0; i < N; i++)
    {
        int ins;
        mon_t m1, m2;
        char *c1;
        void *c2;

        mon_init(m1);
        mon_randtest(m1, state, n, d);

        c1 = malloc(ctx->size);
        ctx->init(ctx, c1);
        ctx->randtest_not_zero(ctx, c1, state);

        ins = RBTREE_INSERT(mpoly, &m2, &c2, rop->dict, m1, c1, &mon_cmp);

        if (ins)
        {
            mon_clear(m2);
            ctx->clear(ctx, c2);
            free(c2);
        }
    }
}
Ejemplo n.º 3
0
static unsigned long meas_bw_and_set_irq(struct bw_hwmon *hw,
					 unsigned int tol, unsigned int us)
{
	unsigned long mbps;
	u32 limit;
	unsigned int sample_ms = hw->df->profile->polling_ms;
	struct bwmon *m = to_bwmon(hw);

	mon_disable(m);

	mbps = mon_get_count(m);
	mbps = bytes_to_mbps(mbps, us);

	/*
	 * If the counter wraps on thres, don't set the thres too low.
	 * Setting it too low runs the risk of the counter wrapping around
	 * multiple times before the IRQ is processed.
	 */
	if (likely(!m->spec->wrap_on_thres))
		limit = mbps_to_bytes(mbps, sample_ms, tol);
	else
		limit = mbps_to_bytes(max(mbps, 400UL), sample_ms, tol);

	mon_set_limit(m, limit);

	mon_clear(m);
	mon_irq_clear(m);
	mon_enable(m);

	dev_dbg(m->dev, "MBps = %lu\n", mbps);
	return mbps;
}
Ejemplo n.º 4
0
static void stop_bw_hwmon(struct bw_hwmon *hw)
{
	struct bwmon *m = to_bwmon(hw);

	mon_irq_disable(m);
	free_irq(m->irq, m);
	mon_disable(m);
	mon_clear(m);
	mon_irq_clear(m);
}
static int resume_bw_hwmon(struct bw_hwmon *hw)
{
	struct bwmon *m = to_bwmon(hw);

	mon_clear(m);
	mon_irq_enable(m);
	mon_enable(m);
	enable_irq(m->irq);

	return 0;
}
static int resume_bw_hwmon(struct bw_hwmon *hw)
{
	struct bwmon *m = to_bwmon(hw);
	int ret;

	mon_clear(m);
	mon_irq_enable(m);
	mon_enable(m);
	ret = request_threaded_irq(m->irq, NULL, bwmon_intr_handler,
				  IRQF_ONESHOT | IRQF_SHARED,
				  dev_name(m->dev), m);
	if (ret) {
		dev_err(m->dev, "Unable to register interrupt handler! (%d)\n",
				ret);
		return ret;
	}

	return 0;
}
static unsigned long meas_bw_and_set_irq(struct bw_hwmon *hw,
					 unsigned int tol, unsigned int us)
{
	unsigned long mbps;
	u32 limit;
	unsigned int sample_ms = hw->df->profile->polling_ms;
	struct bwmon *m = to_bwmon(hw);

	mon_disable(m);

	mbps = mon_get_count(m);
	mbps = bytes_to_mbps(mbps, us);
	/* + 1024 is to workaround HW design issue. Needs further tuning. */
	limit = mbps_to_bytes(mbps + 1024, sample_ms, tol);
	mon_set_limit(m, limit);

	mon_clear(m);
	mon_irq_clear(m);
	mon_enable(m);

	dev_dbg(m->dev, "MBps = %lu\n", mbps);
	return mbps;
}
mon_t * mon_generate_by_degree_invlex(long * len, int n, int d)
{
    mon_t * st;  /* Stack (from the bottom), list (from the top) */
    int * sums;
    int * inds;
    int i;       /* Pointer to the top of the stack */
    int j;       /* Pointer to the bottom of the list */
    int N;       /* $\binom{n-1+d}{d}$ */
    int sum, ind;
    mon_t m;
    exp_t exp;
    
    /* Special case d == 0 */
    if (d == 0)
    {
        st = malloc(sizeof(mon_t));
        if (!st)
        {
            printf("ERROR (mon_generate_by_degree_invlex).  Memory allocation failed.\n");
            abort();
        }
        
        mon_init(st[0]);
        *len = 1;
        return st;
    }
    
    N = mon_binom(n - 1 + d, d);
    
    st   = malloc(N * sizeof(mon_t));
    sums = malloc(N * sizeof(int));
    inds = malloc(N * sizeof(int));
    if (!st || !sums || !inds)
    {
        printf("ERROR (mon_generate_by_degree_invlex).  Memory allocation failed.\n");
        abort();
    }
    
    for (i = 0; i < N; i++)
        mon_init(st[i]);
    
    mon_init(m);
    
    i = 0;
    sums[0] = 0;
    inds[0] = n - 1;
    j = N;
    
    while (i >= 0)
    {
        mon_set(m, st[i]);
        ind = inds[i];
        sum = sums[i];
        i--;
        
        if (ind > 0)
        {
            for (exp = 0; exp <= d - sum; exp++)
            {
                i++;
                mon_set(st[i], m);
                mon_inc_exp(st[i], ind, exp);
                inds[i] = ind - 1;
                sums[i] = sum + exp;
            }
        }
        else
        {
            j--;
            mon_set(st[j], m);
            mon_inc_exp(st[j], ind, d - sum);
        }
    }
    
    mon_clear(m);
    free(sums);
    free(inds);
    
    *len = N;
    return st;
}
Ejemplo n.º 9
0
int
main(void)
{
    int i, result;
    flint_rand_t state;
    ctx_t ctx;

    printf("add_coeff... ");
    fflush(stdout);

    _randinit(state);

    ctx_init_mpq(ctx);

    for (i = 0; i < 1000; i++)
    {
        mpoly_t a;
        long n, d, N;
        mon_t m;
        char *x, *y, *z;

        n = n_randint(state, MON_MAX_VARS) + 1;
        d = n_randint(state, 50) + 1;
        N = n_randint(state, 50) + 1;

        mon_init(m);
        mon_randtest(m, state, n, d);
        x = malloc(ctx->size);
        y = malloc(ctx->size);
        z = malloc(ctx->size);
        ctx->init(ctx, x);
        ctx->init(ctx, y);
        ctx->init(ctx, z);
        ctx->randtest(ctx, x, state);

        mpoly_init(a, n, ctx);
        mpoly_randtest(a, state, d, N, ctx);

        mpoly_get_coeff(y, a, m, ctx);
        ctx->add(ctx, y, y, x);

        mpoly_add_coeff(a, m, x, ctx);
        mpoly_get_coeff(z, a, m, ctx);

        result = (ctx->equal(ctx, y, z));
        if (!result)
        {
            printf("FAIL:\n");
            mpoly_print(a, ctx); printf("\n");
            ctx->print(ctx, x); printf("\n");
            ctx->print(ctx, y); printf("\n");
            ctx->print(ctx, z); printf("\n");
            abort();
        }

        mpoly_clear(a, ctx);
        mon_clear(m);
        ctx->clear(ctx, x);
        ctx->clear(ctx, y);
        ctx->clear(ctx, z);
        free(x);
        free(y);
        free(z);
    }

    _randclear(state);
    _fmpz_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
Ejemplo n.º 10
0
int
main(void)
{
    int i, result;
    flint_rand_t state;
    ctx_t ctx;

    printf("mul_mon... ");
    fflush(stdout);

    _randinit(state);

    ctx_init_mpq(ctx);

    /* Check aliasing of a and b */
    for (i = 0; i < 1000; i++)
    {
        mpoly_t a, b;
        mon_t m;
        long n, d, N;

        n = n_randint(state, MON_MAX_VARS) + 1;
        d = n_randint(state, 50) + 1;
        N = n_randint(state, 50) + 1;

        mon_init(m);
        mon_randtest(m, state, n, d);

        mpoly_init(a, n, ctx);
        mpoly_init(b, n, ctx);
        mpoly_randtest(a, state, d, N, ctx);

        mpoly_mul_mon(b, a, m, ctx);
        mpoly_mul_mon(a, a, m, ctx);

        result = (mpoly_equal(a, b, ctx));
        if (!result)
        {
            printf("FAIL:\n");
            mpoly_print(a, ctx); printf("\n");
            mpoly_print(b, ctx); printf("\n");
            mon_print(m, n); printf("\n");
            abort();
        }

        mpoly_clear(a, ctx);
        mpoly_clear(b, ctx);
        mon_clear(m);
    }

    /* Check (b*c) + (b*d) = b*(c+d) */
    for (i = 0; i < 1000; i++)
    {
        mpoly_t  a1, a2, c1, c2;
        mon_t b;
        long n, d, N;

        n = n_randint(state, MON_MAX_VARS) + 1;
        d = n_randint(state, 50) + 1;
        N = n_randint(state, 50) + 1;

        mon_init(b);
        mon_randtest(b, state, n, d);

        mpoly_init(a1, n, ctx);
        mpoly_init(a2, n, ctx);
        mpoly_init(c1, n, ctx);
        mpoly_init(c2, n, ctx);
        mpoly_randtest(c1, state, d, N, ctx);
        mpoly_randtest(c2, state, d, N, ctx);

        mpoly_mul_mon(a1, c1, b, ctx);
        mpoly_mul_mon(a2, c2, b, ctx);
        mpoly_add(a1, a1, a2, ctx);

        mpoly_add(c1, c1, c2, ctx);
        mpoly_mul_mon(a2, c1, b, ctx);

        result = (mpoly_equal(a1, a2, ctx));
        if (!result)
        {
            printf("FAIL:\n");
            mpoly_print(a1, ctx); printf("\n");
            mpoly_print(a2, ctx); printf("\n");
            mon_print(b, n); printf("\n");
            mpoly_print(c1, ctx); printf("\n");
            mpoly_print(c2, ctx); printf("\n");
            abort();
        }

        mpoly_clear(a1, ctx);
        mpoly_clear(a2, ctx);
        mpoly_clear(c1, ctx);
        mpoly_clear(c2, ctx);
        mon_clear(b);
    }

    _randclear(state);
    _fmpz_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
Ejemplo n.º 11
0
int main(int argc, char *argv[])
{
    mon_t m, m1, m2, *list;
    long i, len;
    char *out, *out1, *out2;

    printf("t-all\n");
    printf("=====\n");
    fflush(stdout);

    /* INIT, FROM_STRING, CLEAR */
    
    mon_init(m);
    mon_set_str(m, "3  1 1 1");
    
    out = mon_get_str(m, 3);
    printf("m = {%s}\n", out);
    free(out);
    
    mon_clear(m);
    
    /* GENERATE_BY_DEGREE */

    printf("Generating all monomials in X, Y, Z of degree 6\n");
    list = mon_generate_by_degree(&len, 3, 6);
    for (i = 0; i < len; i++)
    {
        out = mon_get_str_pretty(list[i], 3, NULL);
        printf("    %s\n", out);
        free(out);
    }
    for (i = 0; i < len; i++)
        mon_clear(list[i]);
    free(list);
    
    printf("Generating all monomials in X, Y, Z of degree 6\n");
    list = mon_generate_by_degree_invlex(&len, 3, 6);
    for (i = 0; i < len; i++)
    {
        out = mon_get_str_pretty(list[i], 3, NULL);
        printf("    %lu - %s\n", list[i], out);
        free(out);
    }
    for (i = 0; i < len; i++)
        mon_clear(list[i]);
    free(list);
    
    /* IS_ONE, DEGREE */

    mon_init(m);
    mon_set_str(m, "3  2 0 1");
    out = mon_get_str_pretty(m, 3, "XYZ");
    printf("Is %s equal to one?  %d\n", out, mon_is_one(m));
    printf("Degree: %d\n", mon_degree(m));
    free(out);
    mon_clear(m);
    
    mon_init(m);
    mon_set_str(m, "3  0 0 0");
    out = mon_get_str_pretty(m, 3, "XYZ");
    printf("Is %s equal to one?  %d\n", out, mon_is_one(m));
    printf("Degree: %d\n", mon_degree(m));
    free(out);
    mon_clear(m);
    
    /* MUL, DIVIDES, INVLEX */
    
    mon_init(m);
    mon_init(m1);
    mon_init(m2);
    mon_set_str(m1, "3  2 0 1");
    mon_set_str(m2, "3  0 1 0");
    mon_mul(m, m1, m2);
    out = mon_get_str_pretty(m, 3, "XYZ");
    printf("Product is [2 0 1] [0 1 0] = %s\n", out);
    free(out);
    printf("Divides?  %d\n", mon_divides(m1, m2));
    printf("INVLEX: %d\n", mon_cmp_invlex(m1, m2));
    mon_clear(m1);
    mon_clear(m2);
    mon_clear(m);
    
    /* DIVIDES, DIV, INVLEX */
    
    mon_init(m);
    mon_init(m1);
    mon_init(m2);
    mon_set_str(m1, "3  1 0 1");
    mon_set_str(m2, "3  1 1 3");
    mon_mul(m, m1, m2);
    out = mon_get_str_pretty(m, 3, "XYZ");
    printf("Product is [1 0 1] [1 1 3] = %s\n", out);
    free(out);
    printf("Divides?  %d\n", mon_divides(m1, m2));
    mon_div(m, m2, m1);
    out = mon_get_str_pretty(m, 3, "XYZ");
    printf("Quotient: %s\n", out);
    free(out);
    printf("INVLEX: %d\n", mon_cmp_invlex(m1, m2));
    mon_clear(m1);
    mon_clear(m2);
    mon_clear(m);
    
    /* INVLEX */
    
    mon_set_str(m1, "3  6 0 0");
    mon_set_str(m2, "3  0 0 6");
    out1 = mon_get_str_pretty(m1, 3, NULL);
    out2 = mon_get_str_pretty(m2, 3, NULL);
    printf("CMP_INVLEX(%s, %s) = %d\n", out1, out2, mon_cmp_invlex(m1, m2));
    free(out1);
    free(out2);

    printf("... ");

    printf("PASS\n");
    fflush(stdout);
    return EXIT_SUCCESS;
}