Autore Topic: Libcpuid14 Extern  (Letto 3523 volte)

Offline eloaders

  • Gamberetto
  • *
  • Post: 38
    • Mostra profilo
Re:Libcpuid14 Extern
« Risposta #15 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?

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.683
  • Ne mors quidem nos iunget
    • Mostra profilo
Re:Libcpuid14 Extern
« Risposta #16 il: 03 Novembre 2016, 15:54:53 »
However, this causes crash interpreter.
Does my code cause crash ? Where (what code line) ?



Is this code you tested and works?
No, I didn't test, because I didn't install that library.


« Ultima modifica: 03 Novembre 2016, 18:16:58 da vuott »
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »

Offline eloaders

  • Gamberetto
  • *
  • Post: 38
    • Mostra profilo
Re:Libcpuid14 Extern
« Risposta #17 il: 03 Novembre 2016, 18:25:27 »
Segfault, it's only what it receives.

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.683
  • Ne mors quidem nos iunget
    • Mostra profilo
Re:Libcpuid14 Extern
« Risposta #18 il: 03 Novembre 2016, 18:30:18 »
We need to know where/when error is raised.

Run the program by pressing F8 (step by step), and see when error is raised.
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »

Offline eloaders

  • Gamberetto
  • *
  • Post: 38
    • Mostra profilo
Re:Libcpuid14 Extern
« Risposta #19 il: 03 Novembre 2016, 18:45:14 »
Segfault in:

Codice: [Seleziona]
    If cpu_identify(raw, data) < 0 Then
      Error.Raise("Sorry, CPU identification failed.\nError: " & cpuid_error())
    Endif
   
    cpu_tsc_mark(mark)
    cpu_tsc_unmark(mark)

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.683
  • Ne mors quidem nos iunget
    • Mostra profilo
Re:Libcpuid14 Extern
« Risposta #20 il: 03 Novembre 2016, 18:55:01 »
Uhmmm.... try this simple code and let me know:

Codice: [Seleziona]
Library "libcpuid:14"

Public Struct cpu_raw_data_t
  basic_cpuid[32, 4] As Integer
  ext_cpuid[32, 4] As Integer
  intel_fn4[4, 4] As Integer
  intel_fn11[4, 4] As Integer
End Struct

Public Struct cpu_mark_t
  tsc As Long
  sys_clock As Long
End Struct

' int cpuid_present(void)
Private Extern cpuid_present() As Integer

' int cpuid_get_raw_data(struct cpu_raw_data_t* data)
Private Extern cpuid_get_raw_data(data As Cpu_raw_data_t) As Integer

' const char* cpuid_error(void)
Private Extern cpuid_error() As String

' int cpu_identify(struct cpu_raw_data_t* raw, struct cpu_id_t* data)
Private Extern cpu_identify(raw As Cpu_raw_data_t, data As Pointer) As Integer

' void cpu_tsc_mark(struct cpu_mark_t* mark)
Private Extern cpu_tsc_mark(mark As Cpu_mark_t)

' void cpu_tsc_unmark(struct cpu_mark_t* mark)
Private Extern cpu_tsc_unmark(mark As Cpu_mark_t)


Public Sub Main()

  Dim raw As New Cpu_raw_data_t
  Dim data As Pointer
  Dim mark As New Cpu_mark_t
 
    If Not cpuid_present() Then Error.Raise("Sorry, your CPU doesn't support CPUID !")
   
    If cpuid_get_raw_data(raw) < 0 Then
      Error.Raise("Sorry, cannot get the CPUID raw data.\nError: " & cpuid_error())
    Endif
   
    data = Alloc(SizeOf(gb.Byte), 392)
   
    If cpu_identify(raw, data) < 0 Then
      Error.Raise("Sorry, CPU identification failed.\nError: " & cpuid_error())
    Endif
   
    cpu_tsc_mark(mark)
    cpu_tsc_unmark(mark)
   
    Free(data)
 
 End
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »

Offline eloaders

  • Gamberetto
  • *
  • Post: 38
    • Mostra profilo
Re:Libcpuid14 Extern
« Risposta #21 il: 03 Novembre 2016, 19:48:08 »
Error occurs in the same place. You are able to execute this code?

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.683
  • Ne mors quidem nos iunget
    • Mostra profilo
Re:Libcpuid14 Extern
« Risposta #22 il: 03 Novembre 2016, 19:52:15 »
You are able to execute this code?
No, I am not.
 I didn't install that library.


Well, please, can you try this other code ?
Codice: [Seleziona]
Library "libcpuid:14"

Public Struct cpu_mark_t
  tsc As Long
  sys_clock As Long
End Struct

' int cpuid_present(void)
Private Extern cpuid_present() As Integer

' int cpuid_get_raw_data(struct cpu_raw_data_t* data)
Private Extern cpuid_get_raw_data(data As Pointer) As Integer

' const char* cpuid_error(void)
Private Extern cpuid_error() As String

' int cpu_identify(struct cpu_raw_data_t* raw, struct cpu_id_t* data)
Private Extern cpu_identify(raw As Pointer, data As Pointer) As Integer

' void cpu_tsc_mark(struct cpu_mark_t* mark)
Private Extern cpu_tsc_mark(mark As Cpu_mark_t)

' void cpu_tsc_unmark(struct cpu_mark_t* mark)
Private Extern cpu_tsc_unmark(mark As Cpu_mark_t)


Public Sub Main()

  Dim raw As Pointer
  Dim data As Pointer
  Dim mark As New Cpu_mark_t
 
    Print Object.SizeOf(raw)
 
    If Not cpuid_present() Then Error.Raise("Sorry, your CPU doesn't support CPUID !")
   
    raw = Alloc(SizeOf(gb.Byte), 1152)
   
    If cpuid_get_raw_data(raw) < 0 Then
      Error.Raise("Sorry, cannot get the CPUID raw data.\nError: " & cpuid_error())
    Endif
   
    data = Alloc(SizeOf(gb.Byte), 392)
   
    If cpu_identify(raw, data) < 0 Then
      Error.Raise("Sorry, CPU identification failed.\nError: " & cpuid_error())
    Endif
   
    cpu_tsc_mark(mark)
    cpu_tsc_unmark(mark)
   
    Free(data)
    Free(raw)
 
 End
« Ultima modifica: 03 Novembre 2016, 19:58:24 da vuott »
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »

Offline eloaders

  • Gamberetto
  • *
  • Post: 38
    • Mostra profilo
Re:Libcpuid14 Extern
« Risposta #23 il: 03 Novembre 2016, 20:00:25 »
Errors by F8

1: Dim mark As New Cpu_mark_t
2: Print Object.SizeOf(raw)

Segfault at Print Object.SizeOf(raw)

And could you install this library?

What could be added to libcpuid to detect the CPU without its combination?
I may write to the author that he added a function that make things easier?

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.683
  • Ne mors quidem nos iunget
    • Mostra profilo
Re:Libcpuid14 Extern
« Risposta #24 il: 03 Novembre 2016, 20:04:23 »

2: Print Object.SizeOf(raw)

Segfault at Print Object.SizeOf(raw)

Oh, what a stupid: I have forgotten to erase that line.
It was only a test.

Well, re-try without Print Object.SizeOf(raw)
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »

Offline eloaders

  • Gamberetto
  • *
  • Post: 38
    • Mostra profilo
Re:Libcpuid14 Extern
« Risposta #25 il: 03 Novembre 2016, 20:08:43 »
Returns Now here's the problem with segfault

Codice: [Seleziona]
gbx3: malloc.c:2392: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (ol
d_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)' failed.

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.683
  • Ne mors quidem nos iunget
    • Mostra profilo
Re:Libcpuid14 Extern
« Risposta #26 il: 03 Novembre 2016, 20:13:11 »
...it seems we have some problem with cpu_id_t Structure.  :-X
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »

Offline eloaders

  • Gamberetto
  • *
  • Post: 38
    • Mostra profilo
Re:Libcpuid14 Extern
« Risposta #27 il: 03 Novembre 2016, 20:19:32 »
Can somehow solve this problem?

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.683
  • Ne mors quidem nos iunget
    • Mostra profilo
Re:Libcpuid14 Extern
« Risposta #28 il: 04 Novembre 2016, 02:21:24 »
Can somehow solve this problem?
Yes, I have to install that library on my system.   ;D

Well, now I installed the libcpuid library, and I can see we had problems with cpu_raw_data_t and cpu_id_t structures declaration !

Now, my code works. 

Here the correct code:

Codice: [Seleziona]
Library "libcpuid:14"

Public Struct cpu_raw_data_t
  basic_cpuid[32, 4] As Integer
  ext_cpuid[32, 4] As Integer
  intel_fn4[8, 4] As Integer
  intel_fn11[4, 4] As Integer
  intel_fn12h[4, 4] As Integer
  intel_fn14h[4, 4] As Integer
End Struct

Public Struct cpu_sgx_t
  present As Integer
  max_enclave_32bit As Byte
  max_enclave_64bit As Byte
  flags[14] As Byte
  num_epc_sections As Integer
  misc_select As Integer
  secs_attributes As Long
  secs_xfrm As Long
End Struct

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
  sgx As Struct Cpu_sgx_t
End Struct

Public Struct cpu_mark_t
  tsc As Long
  sys_clock As Long
End Struct

' int cpuid_present(void)
' Checks if the CPUID instruction is supported.
Private Extern cpuid_present() As Integer

' int cpuid_get_raw_data(struct cpu_raw_data_t* data)
' Obtains the raw CPUID data from the current CPU.
Private Extern cpuid_get_raw_data(data As Cpu_raw_data_t) As Integer

' const char* cpuid_error(void)
' Returns textual description of the last error.
Private Extern cpuid_error() As String

' int cpu_identify(struct cpu_raw_data_t* raw, struct cpu_id_t* data)
' Identifies the CPU.
Private Extern cpu_identify(raw As Cpu_raw_data_t, data As Cpu_id_t) As Integer

' void cpu_tsc_mark(struct cpu_mark_t* mark)
' Store TSC and timing info.
Private Extern cpu_tsc_mark(mark As Cpu_mark_t)

' void cpu_tsc_unmark(struct cpu_mark_t* mark)
' Calculate TSC and timing difference.
Private Extern cpu_tsc_unmark(mark As Cpu_mark_t)

' int cpu_clock(void)
' Get the CPU clock frequency (all-in-one method).
Private Extern cpu_clock() As Integer

' int cpu_clock_by_os(void)
' Returns the CPU clock, as reported by the OS.
Private Extern cpu_clock_by_os() As Integer

' int cpu_clock_by_ic(int millis, int runs)
' Measure the CPU clock frequency using instruction-counting.
Private Extern cpu_clock_by_ic(millis As Integer, runs As Integer) As Integer

' int cpu_clock_measure(int millis, int quad_check)
' Measure the CPU clock frequency.
Private Extern cpu_clock_measure(millis As Integer, quad_check As Integer) As Integer


Public Sub Main()

  Dim raw As New Cpu_raw_data_t
  Dim data As New Cpu_id_t
  Dim mark As New Cpu_mark_t
 
    If Not cpuid_present() Then Error.Raise("Sorry, your CPU doesn't support CPUID !")
   
    If cpuid_get_raw_data(raw) < 0 Then
      Error.Raise("Sorry, cannot get the CPUID raw data.\nError: " & cpuid_error())
    Endif
 
    If cpu_identify(raw, data) < 0 Then
      Error.Raise("Sorry, CPU identification failed.\nError: " & cpuid_error())
    Endif
   
    cpu_tsc_mark(mark)
    cpu_tsc_unmark(mark)
     
End
    :D
« Ultima modifica: 04 Novembre 2016, 15:37:37 da vuott »
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »

Offline eloaders

  • Gamberetto
  • *
  • Post: 38
    • Mostra profilo
Re:Libcpuid14 Extern
« Risposta #29 il: 04 Novembre 2016, 09:00:31 »
Thank you very much. Can I add you to the information about the program? About tab?

One more question. I check the flags by:
Codice: [Seleziona]
 Print data.flags[0]
    Print data.flags[1]
    Print data.flags[89]

But how to know what the flag corresponds to the flags
  • or flags [8]


And yet how it should look SSE_SIZE

in C:
Codice: [Seleziona]
printf("	\"SSE_SIZE\": \"%d bits (%s)\"\n", data.sse_size, data.detection_hints[CPU_HINT_SSE_SIZE_AUTH] ? "authoritative" : "non-authoritative");

Print data.sse_size return me 0, in C return me 64