예제 #1
0
        private void CargarDatosCache(CacheDatos cache, int indiceCache)
        {
            var txtEtiquetas = "";
            var txtValores   = "";
            var txtEstados   = "";

            for (int i = 0; i < CacheDatos.CANTIDAD_BLOQUES; i++)
            {
                txtEtiquetas += cache.GetEtiquetaBloque(i);
                if (i < CacheDatos.CANTIDAD_BLOQUES - 1)
                {
                    txtEtiquetas += " | ";
                }
            }

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < CacheDatos.CANTIDAD_BLOQUES; j++)
                {
                    txtValores += cache.GetPalabraBloque(i, j);
                    if (i < CacheDatos.CANTIDAD_BLOQUES - 1)
                    {
                        txtValores += " | ";
                    }
                    else
                    {
                        txtValores += "\n";
                    }
                }
            }

            for (int i = 0; i < CacheDatos.CANTIDAD_BLOQUES; i++)
            {
                txtEstados += cache.GetEstadoBloque(i);
                if (i < CacheDatos.CANTIDAD_BLOQUES - 1)
                {
                    txtEstados += " | ";
                }
            }

            if (indiceCache == 0)
            {
                tbCache0Estados.Text   = txtEstados;
                tbCache0Valores.Text   = txtValores;
                tbCache0Etiquetas.Text = txtEtiquetas;
            }
            else
            {
                tbCache1Estados.Text   = txtEstados;
                tbCache1Valores.Text   = txtValores;
                tbCache1Etiquetas.Text = txtEtiquetas;
            }
        }
예제 #2
0
        private int LoadWord(int regFuente2, int posMem)
        {
            int  resultado = 0;
            bool detenido;
            int  nBloque        = GetNumeroBloque(posMem);
            int  nPalabra       = GetNumeroPalabra(posMem, 4);
            int  nBloqueEnCache = GetPosicionCache(nBloque);

            CacheDatos.BloqueCacheDatos elBloque;
            CacheDatos.BloqueCacheDatos elBloqueV;

            do
            {
                detenido = false;
                if (Monitor.TryEnter(cacheDatos.bloques[nBloqueEnCache]))
                {
                    try
                    {
                        elBloque = cacheDatos.GetBloque(nBloqueEnCache);
                        //elBloqueV = cacheDatos.GetBloque(nBloqueEnCache);
                        if (elBloque.GetEtiqueta() == nBloque)
                        {
                            if (elBloque.GetEstado() == CacheDatos.BloqueCacheDatos.Estado.C || elBloque.GetEstado() == CacheDatos.BloqueCacheDatos.Estado.M)
                            {
                                //AvanzarReloj(1);                // Bloque esta en la cache, todo bien // Ya sumo en otro lado
                            }
                            else
                            {
                                //El bloque está Inválido
                                if (Monitor.TryEnter(busDatos))
                                {
                                    try
                                    {
                                        CacheDatos.BloqueCacheDatos bloqueOtraCache;
                                        var otroNucleo = 0;
                                        if (identificador == 0)
                                        {
                                            otroNucleo = 1;
                                        }

                                        if (Monitor.TryEnter(busDatos.GetBloqueCache(otroNucleo, nBloqueEnCache)))
                                        {
                                            try
                                            {
                                                bloqueOtraCache = busDatos.GetBloqueCache(otroNucleo, nBloqueEnCache);
                                                if (bloqueOtraCache.GetEtiqueta() == nBloque)
                                                {
                                                    if (bloqueOtraCache.GetEstado() == CacheDatos.BloqueCacheDatos.Estado.M)
                                                    {
                                                        busDatos.BloqueAMem(bloqueOtraCache, nBloque);
                                                        busDatos.CambiarEstadoBloqueCache(otroNucleo, nBloqueEnCache, CacheDatos.BloqueCacheDatos.Estado.C);
                                                        cacheDatos.SetBloque(nBloqueEnCache, bloqueOtraCache);
                                                        AvanzarReloj(CICLOS_COPIAR_A_MEMORIA);
                                                        AvanzarReloj(1);
                                                    }
                                                }
                                                else
                                                {
                                                    cacheDatos.SetBloque(nBloqueEnCache, busDatos.BloqueDeMem(nBloque));
                                                    AvanzarReloj(CICLOS_TRAER_DE_MEMORIA);
                                                    AvanzarReloj(1);
                                                }
                                            }
                                            finally
                                            {
                                                Monitor.Exit(busDatos.GetBloqueCache(otroNucleo, nBloqueEnCache));
                                            }
                                        }
                                    }

                                    finally
                                    {
                                        Monitor.Exit(busDatos);
                                    }
                                }
                                else
                                {
                                    //Detenido en ejecución con IR listo
                                    detenido = true;
                                    AvanzarReloj(1);
                                }
                            }
                        }
                        else
                        {
                            // Reviso si mi bloque esta modificado, el que esta en la cache, de estarlo debo guardarlo en memoria. Hay un FALLO DE CACHE
                            if (Monitor.TryEnter(busDatos))
                            {
                                try
                                {
                                    if (elBloque.GetEstado() == CacheDatos.BloqueCacheDatos.Estado.M)   // bloque victima
                                    {
                                        busDatos.BloqueAMem(elBloque, elBloque.GetEtiqueta());
                                        busDatos.CambiarEstadoBloqueCache(identificador, nBloqueEnCache, CacheDatos.BloqueCacheDatos.Estado.C);
                                        AvanzarReloj(CICLOS_COPIAR_A_MEMORIA);
                                    }
                                    else
                                    {   // revisa la otra cache para ver si lo encuentra alla.
                                        CacheDatos.BloqueCacheDatos bloqueOtraCache;
                                        var otroNucleo = 0;
                                        if (identificador == 0)
                                        {
                                            otroNucleo = 1;
                                        }

                                        if (Monitor.TryEnter(busDatos.GetBloqueCache(otroNucleo, nBloqueEnCache)))
                                        {
                                            try
                                            {
                                                bloqueOtraCache = busDatos.GetBloqueCache(otroNucleo, nBloqueEnCache);
                                                if (bloqueOtraCache.GetEtiqueta() == nBloque)
                                                {
                                                    if (bloqueOtraCache.GetEstado() == CacheDatos.BloqueCacheDatos.Estado.M)
                                                    {
                                                        busDatos.BloqueAMem(bloqueOtraCache, nBloque);
                                                        busDatos.CambiarEstadoBloqueCache(otroNucleo, nBloqueEnCache, CacheDatos.BloqueCacheDatos.Estado.C);
                                                        cacheDatos.SetBloque(nBloqueEnCache, bloqueOtraCache);      // copia de la otra cache a la de el.
                                                        AvanzarReloj(CICLOS_COPIAR_A_MEMORIA);
                                                        AvanzarReloj(1);
                                                    }
                                                }
                                                else
                                                {
                                                    cacheDatos.SetBloque(nBloqueEnCache, busDatos.BloqueDeMem(nBloque));
                                                    AvanzarReloj(CICLOS_TRAER_DE_MEMORIA);
                                                    AvanzarReloj(1);
                                                }
                                            }
                                            finally
                                            {
                                                Monitor.Exit(busDatos.GetBloqueCache(otroNucleo, nBloqueEnCache));
                                            }
                                        }
                                    }
                                }

                                finally
                                {
                                    Monitor.Exit(busDatos);
                                }
                            }
                        }
                    }

                    finally
                    {
                        //Libera la posición de caché
                        resultado = cacheDatos.GetPalabraBloque(nBloqueEnCache, nPalabra);
                        Monitor.Exit(cacheDatos.bloques[nBloqueEnCache]);
                    }
                }
                else
                {
                    AvanzarReloj(1);
                    detenido = true;
                }
            } while (detenido);

            return(resultado);
        }