31
Programmazione / Re:Libcpuid14 Extern
« il: 03 Novembre 2016, 08:52:13 »
Already we are closer to what he wants. However, this causes crash interpreter.
Is this code you tested and works?
Is this code you tested and works?
19/05/2023: A causa di un errore sono stati cancellati, insieme ad account creati da bot, alcuni account legittimi. Si prega di leggere qui: https://www.gambas-it.org/smf/index.php?topic=9733.0
Questa sezione ti permette di visualizzare tutti i post inviati da questo utente. N.B: puoi vedere solo i post relativi alle aree dove hai l'accesso.
#include <stdio.h>
#include <libcpuid.h>
int main(void)
{
if (!cpuid_present()) { // check for CPUID presence
printf("Sorry, your CPU doesn't support CPUID!\n");
return -1;
}
struct cpu_raw_data_t raw;
struct cpu_id_t data; // contains recognized CPU features data
if (cpuid_get_raw_data(&raw) < 0) { // obtain the raw CPUID data
printf("Sorry, cannot get the CPUID raw data.\n");
printf("Error: %s\n", cpuid_error()); // cpuid_error() gives the last error description
return -2;
}
if (cpu_identify(&raw, &data) < 0) { // identify the CPU, using the given raw data.
printf("Sorrry, CPU identification failed.\n");
printf("Error: %s\n", cpuid_error());
return -3;
}
struct cpu_mark_t mark;
cpu_tsc_mark(&mark);
cpu_tsc_unmark(&mark);
printf("{\n");
printf(" \"VENDOR_STR\": \"%s\",\n", data.vendor_str); //
printf(" \"CPU_CODENAME\": \"%s\",\n", data.cpu_codename); //
printf(" \"BRAND_STR\": \"%s\",\n", data.brand_str); //
printf(" \"NUM_CORES\": \"%d\",\n", data.num_cores); //
printf(" \"NUM_LOGICAL_CPUS\": \"%d\",\n", data.num_logical_cpus); //
printf(" \"TOTAL_LOGICAL_CPUS\": \"%d\",\n", data.total_logical_cpus); //
printf(" \"FAMILY\": \"%d\",\n", data.family); //
printf(" \"MODEL\": \"%d\",\n", data.model); //
printf(" \"STEPPING\": \"%d\",\n", data.stepping); //
printf(" \"EXT_FAMILY\": \"%d\",\n", data.ext_family); //
printf(" \"EXT_MODEL\": \"%d\",\n", data.ext_model); //
printf(" \"CPU_CLOCK\": \"%d MHz\",\n", cpu_clock()); //
printf(" \"CPU_CLOCK_BY_OS\": \"%d MHz\",\n", cpu_clock_by_os()); //
printf(" \"CPU_CLOCK_BY_IC\": \"%d MHz\",\n", cpu_clock_by_ic(25, 16)); //
printf(" \"CPU_CLOCK_MEASURE\": \"%d MHz\",\n", cpu_clock_measure(400, 1));//
printf(" \"MARK_TSC\": \"%llu\",\n", mark.tsc); //
printf(" \"MARK_SYS_CLOCK\": \"%llu\",\n", mark.sys_clock); //
' Gambas module file
Library "libcpuid:14"
Public Struct cpu_id_t
vendor_str[16] As Byte
brand_str[64] As Byte
vendor As Integer
flags[128] As Byte
family As Integer
model As Integer
stepping As Integer
ext_family As Integer
ext_model As Integer
num_cores As Integer
num_logical_cpus As Integer
total_logical_cpus As Integer
l1_data_cache As Integer
l1_instruction_cache As Integer
l2_cache As Integer
l3_cache As Integer
l4_cache As Integer
l1_assoc As Integer
l2_assoc As Integer
l3_assoc As Integer
l4_assoc As Integer
l1_cacheline As Integer
l2_cacheline As Integer
l3_cacheline As Integer
l4_cacheline As Integer
cpu_codename[64] As Byte
sse_size As Integer
detection_hints[16] As Byte
End Struct
Private cpu_id_t As New Cpu_id_t
'Private Extern cpu_id_t(info As Cpu_id_t) As Integer
Public Sub Main()
Dim si As New Cpu_id_t
Print si.l1_assoc
Print si.sse_size
Print si.vendor
End
' Gambas module file
Library "libc:6"
Public Struct sysinfo
uptime As Long
loads[3] As Long
totalram As Long
freeram As Long
sharedram As Long
bufferram As Long
totalswap As Long
freeswap As Long
procs As Short
pad As Short
totalhigh As Long
freehigh As Long
mem_unit As Integer
End Struct
' int sysinfo (struct sysinfo *__info)
' Returns information on overall system statistics.
Private Extern sysinfo(info As Sysinfo) As Integer
Public Logs As New Logger
Public Sub Main()
Dim si As New Sysinfo
Dim err As Integer
err = sysinfo(si)
If err < 0 Then
Logs("Libc6 Sysinfo Error", Logger.Error)
Else
Finfosys.TextBox58.Text = "Uptime: " & Date(0, 0, 0, 0, 0, 0, CInt(si.uptime * 1000))
Endif
End
' Gambas module file
Library "libcpuid:14"
Public Struct cpu_id_t
vendor_str[64] As String
brand_str[64] As String
vendor As String
flags[256] As Byte
family As Integer
model As Integer
stepping As Integer
ext_family As Integer
ext_model As Integer
num_cores As Integer
num_logical_cpus As Integer
total_logical_cpus As Integer
l1_data_cache As Integer
l1_instruction_cache As Integer
l2_cache As Integer
l3_cache As Integer
l4_cache As Integer
l1_assoc As Integer
l2_assoc As Integer
l3_assoc As Integer
l4_assoc As Integer
l1_cacheline As Integer
l2_cacheline As Integer
l3_cacheline As Integer
l4_cacheline As Integer
cpu_codename[64] As String
sse_size As Integer
detection_hints[128] As Byte
End Struct
Private cpu_id_t As New Cpu_id_t
'Private Extern cpu_id_t(info As Cpu_id_t) As Integer
Public Sub Main()
Dim si As New Cpu_id_t
Print si.l1_assoc
End