<commit_before>#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#include "knc-asic.h"

#include "knc-transport.h"

#include "logging.h"

#define UNUSED __attribute__((unused))

struct knc_die_info die_info;

#define chip_version (die_info.version)

static void detect_chip(void *ctx, int channel, int die)
{
	if (chip_version != KNC_VERSION_UNKNOWN)
		return;

	if (knc_detect_die(ctx, channel, die, &die_info) != 0) {
		printf("ERROR: No asic found\n");
		exit(1);
	}
	chip_version = die_info.version;
}

static void do_info(void *ctx, int channel, int die, UNUSED int argc, UNUSED char **args)
{
	detect_chip(ctx, channel, die);

	if (knc_detect_die(ctx, channel, die, &die_info) != 0) {
		printf("ERROR: No asic found\n");
		exit(1);
	}

	printf("Version: %d\n", die_info.version);
	printf("Cores: %d\n", die_info.cores);
	if (die_info.pll_power_down >= 0) printf("PLL power: %s\n", die_info.pll_power_down ? "DOWN" : "UP");
	if (die_info.pll_locked >= 0)     printf("PLL status: %s\n", die_info.pll_locked ? "GOOD" : "BAD");
	if (die_info.hash_reset_n >= 0)   printf("HASH reset: %s\n", die_info.hash_reset_n ? "NORMAL" : "RESET");
	if (die_info.pll_reset_n >= 0)    printf("PLL reset: %s\n", die_info.pll_reset_n ? "NORMAL" : "RESET");
	printf("Want work: ");
	int core;
	for (core = 0; core < die_info.cores; core++) {
		putchar(die_info.want_work[core] == 0 ? '.' :
		        die_info.want_work[core] == 1 ? '*' :
		        '?');
	}
	putchar('\n');
	chip_version = die_info.version;
}

static int hex_decode(uint8_t *dst, const char *src, size_t max_len)
{
	size_t len = 0;
	int dir = 1;
	memset(dst, 0, max_len);
	if (strncmp(src, "0x", 2) == 0 || strncmp(src, "0X", 2) == 0) {
		src += 2;<commit_msg>asic info: Skip chip detection. We need the very first asic info report for correct pll status bits<commit_after>#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#include "knc-asic.h"

#include "knc-transport.h"

#include "logging.h"

#define UNUSED __attribute__((unused))

struct knc_die_info die_info;

#define chip_version (die_info.version)

static void detect_chip(void *ctx, int channel, int die)
{
	if (chip_version != KNC_VERSION_UNKNOWN)
		return;

	if (knc_detect_die(ctx, channel, die, &die_info) != 0) {
		printf("ERROR: No asic found\n");
		exit(1);
	}
	chip_version = die_info.version;
}

static void do_info(void *ctx, int channel, int die, UNUSED int argc, UNUSED char **args)
{
	if (knc_detect_die(ctx, channel, die, &die_info) != 0) {
		printf("ERROR: No asic found\n");
		exit(1);
	}

	printf("Version: %d\n", die_info.version);
	printf("Cores: %d\n", die_info.cores);
	if (die_info.pll_power_down >= 0) printf("PLL power: %s\n", die_info.pll_power_down ? "DOWN" : "UP");
	if (die_info.pll_locked >= 0)     printf("PLL status: %s\n", die_info.pll_locked ? "GOOD" : "BAD");
	if (die_info.hash_reset_n >= 0)   printf("HASH reset: %s\n", die_info.hash_reset_n ? "NORMAL" : "RESET");
	if (die_info.pll_reset_n >= 0)    printf("PLL reset: %s\n", die_info.pll_reset_n ? "NORMAL" : "RESET");
	printf("Want work: ");
	int core;
	for (core = 0; core < die_info.cores; core++) {
		putchar(die_info.want_work[core] == 0 ? '.' :
		        die_info.want_work[core] == 1 ? '*' :
		        '?');
	}
	putchar('\n');
	chip_version = die_info.version;
}

static int hex_decode(uint8_t *dst, const char *src, size_t max_len)
{
	size_t len = 0;
	int dir = 1;
	memset(dst, 0, max_len);
	if (strncmp(src, "0x", 2) == 0 || strncmp(src, "0X", 2) == 0) {
		src += 2;
{'fraction_non_alphanumeric': 0.17787114845938376, 'fraction_numerical': 0.012324929971988795, 'mean_word_length': 4.361861861861862, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 21, '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': '3410033', 'n_tokens_mistral': 1548, 'n_tokens_neox': 1454, 'n_words': 345}